identity.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright 2021-2023 Glen Joseph Fernandes
  3. ([email protected])
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_CORE_IDENTITY_HPP
  8. #define BOOST_CORE_IDENTITY_HPP
  9. #include <boost/config.hpp>
  10. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  11. #include <utility>
  12. #endif
  13. namespace boost {
  14. struct identity {
  15. typedef void is_transparent;
  16. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  17. template<class T>
  18. BOOST_CONSTEXPR T&& operator()(T&& value) const BOOST_NOEXCEPT {
  19. return std::forward<T>(value);
  20. }
  21. #else
  22. template<class T>
  23. BOOST_CONSTEXPR const T& operator()(const T& value) const BOOST_NOEXCEPT {
  24. return value;
  25. }
  26. template<class T>
  27. BOOST_CONSTEXPR T& operator()(T& value) const BOOST_NOEXCEPT {
  28. return value;
  29. }
  30. #endif
  31. template<class>
  32. struct result { };
  33. template<class T>
  34. struct result<identity(T&)> {
  35. typedef T& type;
  36. };
  37. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  38. template<class T>
  39. struct result<identity(T)> {
  40. typedef T&& type;
  41. };
  42. template<class T>
  43. struct result<identity(T&&)> {
  44. typedef T&& type;
  45. };
  46. #endif
  47. };
  48. } /* boost */
  49. #endif