equality_comparable.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // traits/equality_comparable.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP
  11. #define BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #if defined(BOOST_ASIO_HAS_DECLTYPE) \
  18. && defined(BOOST_ASIO_HAS_NOEXCEPT) \
  19. && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. # define BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT 1
  21. #endif // defined(BOOST_ASIO_HAS_DECLTYPE)
  22. // && defined(BOOST_ASIO_HAS_NOEXCEPT)
  23. // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  24. namespace boost {
  25. namespace asio {
  26. namespace traits {
  27. template <typename T, typename = void>
  28. struct equality_comparable_default;
  29. template <typename T, typename = void>
  30. struct equality_comparable;
  31. } // namespace traits
  32. namespace detail {
  33. struct no_equality_comparable
  34. {
  35. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false);
  36. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
  37. };
  38. #if defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  39. template <typename T, typename = void>
  40. struct equality_comparable_trait : no_equality_comparable
  41. {
  42. };
  43. template <typename T>
  44. struct equality_comparable_trait<T,
  45. typename void_type<
  46. decltype(
  47. static_cast<void>(
  48. static_cast<bool>(declval<const T>() == declval<const T>())
  49. ),
  50. static_cast<void>(
  51. static_cast<bool>(declval<const T>() != declval<const T>())
  52. )
  53. )
  54. >::type>
  55. {
  56. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  57. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  58. noexcept(declval<const T>() == declval<const T>())
  59. && noexcept(declval<const T>() != declval<const T>()));
  60. };
  61. #else // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  62. template <typename T, typename = void>
  63. struct equality_comparable_trait :
  64. conditional<
  65. is_same<T, typename decay<T>::type>::value,
  66. no_equality_comparable,
  67. traits::equality_comparable<typename decay<T>::type>
  68. >::type
  69. {
  70. };
  71. #endif // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  72. } // namespace detail
  73. namespace traits {
  74. template <typename T, typename>
  75. struct equality_comparable_default : detail::equality_comparable_trait<T>
  76. {
  77. };
  78. template <typename T, typename>
  79. struct equality_comparable : equality_comparable_default<T>
  80. {
  81. };
  82. } // namespace traits
  83. } // namespace asio
  84. } // namespace boost
  85. #endif // BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP