identity.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. template <class Ty> struct identity {
  23. using argument_type = Ty;
  24. Ty &operator()(Ty &self) const {
  25. return self;
  26. }
  27. const Ty &operator()(const Ty &self) const {
  28. return self;
  29. }
  30. };
  31. } // end namespace llvm
  32. #endif // LLVM_ADT_IDENTITY_H
  33. #ifdef __GNUC__
  34. #pragma GCC diagnostic pop
  35. #endif