equality_comparable.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // traits/equality_comparable.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_WORKING_EXPRESSION_SFINAE)
  18. # define BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT 1
  19. #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE)
  20. namespace boost {
  21. namespace asio {
  22. namespace traits {
  23. template <typename T, typename = void>
  24. struct equality_comparable_default;
  25. template <typename T, typename = void>
  26. struct equality_comparable;
  27. } // namespace traits
  28. namespace detail {
  29. struct no_equality_comparable
  30. {
  31. static constexpr bool is_valid = false;
  32. static constexpr bool is_noexcept = false;
  33. };
  34. #if defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  35. template <typename T, typename = void>
  36. struct equality_comparable_trait : no_equality_comparable
  37. {
  38. };
  39. template <typename T>
  40. struct equality_comparable_trait<T,
  41. void_t<
  42. decltype(
  43. static_cast<void>(
  44. static_cast<bool>(declval<const T>() == declval<const T>())
  45. ),
  46. static_cast<void>(
  47. static_cast<bool>(declval<const T>() != declval<const T>())
  48. )
  49. )
  50. >>
  51. {
  52. static constexpr bool is_valid = true;
  53. static constexpr bool is_noexcept =
  54. noexcept(declval<const T>() == declval<const T>())
  55. && noexcept(declval<const T>() != declval<const T>());
  56. };
  57. #else // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  58. template <typename T, typename = void>
  59. struct equality_comparable_trait :
  60. conditional_t<
  61. is_same<T, decay_t<T>>::value,
  62. no_equality_comparable,
  63. traits::equality_comparable<decay_t<T>>
  64. >
  65. {
  66. };
  67. #endif // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  68. } // namespace detail
  69. namespace traits {
  70. template <typename T, typename>
  71. struct equality_comparable_default : detail::equality_comparable_trait<T>
  72. {
  73. };
  74. template <typename T, typename>
  75. struct equality_comparable : equality_comparable_default<T>
  76. {
  77. };
  78. } // namespace traits
  79. } // namespace asio
  80. } // namespace boost
  81. #endif // BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP