concepts.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*!
  2. @file
  3. Defines concepts from the Standard library.
  4. @copyright Louis Dionne 2013-2016
  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. //////////////////////////////////////////////////////////////////////////
  16. // EqualityComparable
  17. //////////////////////////////////////////////////////////////////////////
  18. template <typename T, typename U = T, typename = void>
  19. struct EqualityComparable : std::false_type { };
  20. template <typename T>
  21. struct EqualityComparable<T, T, detail::void_t<
  22. decltype(static_cast<T&&>(*(T*)0) == static_cast<T&&>(*(T*)0) ? 0:0),
  23. decltype(static_cast<T&&>(*(T*)0) != static_cast<T&&>(*(T*)0) ? 0:0)
  24. >> : std::true_type { };
  25. template <typename T, typename U>
  26. struct EqualityComparable<T, U, typename std::enable_if<
  27. !std::is_same<T, U>{}, detail::void_t<
  28. decltype(static_cast<T&&>(*(T*)0) == static_cast<U&&>(*(U*)0) ? 0:0),
  29. decltype(static_cast<U&&>(*(U*)0) == static_cast<T&&>(*(T*)0) ? 0:0),
  30. decltype(static_cast<T&&>(*(T*)0) != static_cast<U&&>(*(U*)0) ? 0:0),
  31. decltype(static_cast<U&&>(*(U*)0) != static_cast<T&&>(*(T*)0) ? 0:0),
  32. typename detail::std_common_type<T, U>::type
  33. >>::type> : std::integral_constant<bool,
  34. EqualityComparable<T>::value &&
  35. EqualityComparable<U>::value &&
  36. EqualityComparable<typename detail::std_common_type<T, U>::type>::value
  37. > { };
  38. //////////////////////////////////////////////////////////////////////////
  39. // LessThanComparable
  40. //////////////////////////////////////////////////////////////////////////
  41. template <typename T, typename U = T, typename = void>
  42. struct LessThanComparable : std::false_type { };
  43. template <typename T>
  44. struct LessThanComparable<T, T, detail::void_t<
  45. decltype(static_cast<T&&>(*(T*)0) < static_cast<T&&>(*(T*)0) ? 0:0)
  46. >> : std::true_type { };
  47. template <typename T, typename U>
  48. struct LessThanComparable<T, U, std::enable_if_t<
  49. !std::is_same<T, U>::value,
  50. detail::void_t<
  51. decltype(static_cast<T&&>(*(T*)0) < static_cast<U&&>(*(U*)0) ? 0:0),
  52. decltype(static_cast<U&&>(*(U*)0) < static_cast<T&&>(*(T*)0) ? 0:0),
  53. typename detail::std_common_type<T, U>::type
  54. >
  55. >>
  56. : std::integral_constant<bool,
  57. LessThanComparable<T>::value &&
  58. LessThanComparable<U>::value &&
  59. LessThanComparable<typename detail::std_common_type<T, U>::type>::value
  60. >
  61. { };
  62. } BOOST_HANA_NAMESPACE_END
  63. #endif // !BOOST_HANA_DETAIL_CONCEPTS_HPP