equality_comparable.hpp 2.6 KB

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