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 11 #ifndef BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP 12 #define BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/asio/detail/config.hpp> 19 #include <boost/asio/detail/type_traits.hpp> 20 21 #if defined(BOOST_ASIO_HAS_DECLTYPE) \ 22 && defined(BOOST_ASIO_HAS_NOEXCEPT) \ 23 && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) 24 # define BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT 1 25 #endif // defined(BOOST_ASIO_HAS_DECLTYPE) 26 // && defined(BOOST_ASIO_HAS_NOEXCEPT) 27 // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) 28 29 namespace boost { 30 namespace asio { 31 namespace traits { 32 33 template <typename T, typename = void> 34 struct equality_comparable_default; 35 36 template <typename T, typename = void> 37 struct equality_comparable; 38 39 } // namespace traits 40 namespace detail { 41 42 struct no_equality_comparable 43 { 44 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = false); 45 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false); 46 }; 47 48 #if defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) 49 50 template <typename T, typename = void> 51 struct equality_comparable_trait : no_equality_comparable 52 { 53 }; 54 55 template <typename T> 56 struct equality_comparable_trait<T, 57 typename void_type< 58 decltype( 59 static_cast<void>( 60 static_cast<bool>(declval<const T>() == declval<const T>()) 61 ), 62 static_cast<void>( 63 static_cast<bool>(declval<const T>() != declval<const T>()) 64 ) 65 ) 66 >::type> 67 { 68 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); 69 70 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = 71 noexcept(declval<const T>() == declval<const T>()) 72 && noexcept(declval<const T>() != declval<const T>())); 73 }; 74 75 #else // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) 76 77 template <typename T, typename = void> 78 struct equality_comparable_trait : 79 conditional< 80 is_same<T, typename decay<T>::type>::value, 81 no_equality_comparable, 82 traits::equality_comparable<typename decay<T>::type> 83 >::type 84 { 85 }; 86 87 #endif // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) 88 89 } // namespace detail 90 namespace traits { 91 92 template <typename T, typename> 93 struct equality_comparable_default : detail::equality_comparable_trait<T> 94 { 95 }; 96 97 template <typename T, typename> 98 struct equality_comparable : equality_comparable_default<T> 99 { 100 }; 101 102 } // namespace traits 103 } // namespace asio 104 } // namespace boost 105 106 #endif // BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP 107