equality_comparable.hpp 2.4 KB

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