identity.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___FUNCTIONAL_IDENTITY_H
  10. #define _LIBCPP___FUNCTIONAL_IDENTITY_H
  11. #include <__config>
  12. #include <__type_traits/integral_constant.h>
  13. #include <__utility/forward.h>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. template <class _Tp>
  19. struct __is_identity : false_type {};
  20. struct __identity {
  21. template <class _Tp>
  22. _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT {
  23. return std::forward<_Tp>(__t);
  24. }
  25. using is_transparent = void;
  26. };
  27. template <>
  28. struct __is_identity<__identity> : true_type {};
  29. #if _LIBCPP_STD_VER >= 20
  30. struct identity {
  31. template<class _Tp>
  32. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator()(_Tp&& __t) const noexcept
  33. {
  34. return _VSTD::forward<_Tp>(__t);
  35. }
  36. using is_transparent = void;
  37. };
  38. template <>
  39. struct __is_identity<identity> : true_type {};
  40. #endif // _LIBCPP_STD_VER >= 20
  41. _LIBCPP_END_NAMESPACE_STD
  42. #endif // _LIBCPP___FUNCTIONAL_IDENTITY_H