concepts.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*!
  2. @file
  3. Defines concepts from the Standard library.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_DETAIL_CONCEPTS_HPP
  9. #define BOOST_HANA_DETAIL_CONCEPTS_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/detail/std_common_type.hpp>
  12. #include <boost/hana/detail/void_t.hpp>
  13. #include <type_traits>
  14. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  15. //! @cond
  16. //////////////////////////////////////////////////////////////////////////
  17. // EqualityComparable
  18. //////////////////////////////////////////////////////////////////////////
  19. template <typename T, typename U = T, typename = void>
  20. struct EqualityComparable : std::false_type { };
  21. template <typename T>
  22. struct EqualityComparable<T, T, detail::void_t<
  23. decltype(static_cast<T&&>(*(T*)0) == static_cast<T&&>(*(T*)0) ? 0:0),
  24. decltype(static_cast<T&&>(*(T*)0) != static_cast<T&&>(*(T*)0) ? 0:0)
  25. >> : std::true_type { };
  26. template <typename T, typename U>
  27. struct EqualityComparable<T, U, typename std::enable_if<
  28. !std::is_same<T, U>::value, detail::void_t<
  29. decltype(static_cast<T&&>(*(T*)0) == static_cast<U&&>(*(U*)0) ? 0:0),
  30. decltype(static_cast<U&&>(*(U*)0) == static_cast<T&&>(*(T*)0) ? 0:0),
  31. decltype(static_cast<T&&>(*(T*)0) != static_cast<U&&>(*(U*)0) ? 0:0),
  32. decltype(static_cast<U&&>(*(U*)0) != static_cast<T&&>(*(T*)0) ? 0:0),
  33. typename detail::std_common_type<T, U>::type
  34. >>::type> : std::integral_constant<bool,
  35. EqualityComparable<T>::value &&
  36. EqualityComparable<U>::value &&
  37. EqualityComparable<typename detail::std_common_type<T, U>::type>::value
  38. > { };
  39. //////////////////////////////////////////////////////////////////////////
  40. // LessThanComparable
  41. //////////////////////////////////////////////////////////////////////////
  42. template <typename T, typename U = T, typename = void>
  43. struct LessThanComparable : std::false_type { };
  44. template <typename T>
  45. struct LessThanComparable<T, T, detail::void_t<
  46. decltype(static_cast<T&&>(*(T*)0) < static_cast<T&&>(*(T*)0) ? 0:0)
  47. >> : std::true_type { };
  48. template <typename T, typename U>
  49. struct LessThanComparable<T, U, std::enable_if_t<
  50. !std::is_same<T, U>::value,
  51. detail::void_t<
  52. decltype(static_cast<T&&>(*(T*)0) < static_cast<U&&>(*(U*)0) ? 0:0),
  53. decltype(static_cast<U&&>(*(U*)0) < static_cast<T&&>(*(T*)0) ? 0:0),
  54. typename detail::std_common_type<T, U>::type
  55. >
  56. >>
  57. : std::integral_constant<bool,
  58. LessThanComparable<T>::value &&
  59. LessThanComparable<U>::value &&
  60. LessThanComparable<typename detail::std_common_type<T, U>::type>::value
  61. >
  62. { };
  63. //! @endcond
  64. } BOOST_HANA_NAMESPACE_END
  65. #endif // !BOOST_HANA_DETAIL_CONCEPTS_HPP