1 // 2 // traits/equality_comparable.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2020 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<bool>(declval<const T>() == declval<const T>()), 60 static_cast<bool>(declval<const T>() != declval<const T>()) 61 ) 62 >::type> 63 { 64 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); 65 66 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = 67 noexcept(declval<const T>() == declval<const T>()) 68 && noexcept(declval<const T>() != declval<const T>())); 69 }; 70 71 #else // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) 72 73 template <typename T, typename = void> 74 struct equality_comparable_trait : 75 conditional< 76 is_same<T, typename decay<T>::type>::value, 77 no_equality_comparable, 78 traits::equality_comparable<typename decay<T>::type> 79 >::type 80 { 81 }; 82 83 #endif // defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT) 84 85 } // namespace detail 86 namespace traits { 87 88 template <typename T, typename> 89 struct equality_comparable_default : detail::equality_comparable_trait<T> 90 { 91 }; 92 93 template <typename T, typename> 94 struct equality_comparable : equality_comparable_default<T> 95 { 96 }; 97 98 } // namespace traits 99 } // namespace asio 100 } // namespace boost 101 102 #endif // BOOST_ASIO_TRAITS_EQUALITY_COMPARABLE_HPP 103