identity.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/ADT/Identity.h - Provide std::identity from C++20 ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file provides an implementation of std::identity from C++20.
  15. //
  16. // No library is required when using these functions.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_ADT_IDENTITY_H
  20. #define LLVM_ADT_IDENTITY_H
  21. namespace llvm {
  22. // Similar to `std::identity` from C++20.
  23. template <class Ty> struct identity {
  24. using is_transparent = void;
  25. using argument_type = Ty;
  26. Ty &operator()(Ty &self) const {
  27. return self;
  28. }
  29. const Ty &operator()(const Ty &self) const {
  30. return self;
  31. }
  32. };
  33. } // end namespace llvm
  34. #endif // LLVM_ADT_IDENTITY_H
  35. #ifdef __GNUC__
  36. #pragma GCC diagnostic pop
  37. #endif