| 1 | // |
| 2 | // traits/static_require.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 | |
| 11 | #ifndef BOOST_ASIO_TRAITS_STATIC_REQUIRE_HPP |
| 12 | #define BOOST_ASIO_TRAITS_STATIC_REQUIRE_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 | #include <boost/asio/traits/static_query.hpp> |
| 21 | |
| 22 | #define BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT 1 |
| 23 | |
| 24 | #include <boost/asio/detail/push_options.hpp> |
| 25 | |
| 26 | namespace boost { |
| 27 | namespace asio { |
| 28 | namespace traits { |
| 29 | |
| 30 | template <typename T, typename Property, typename = void> |
| 31 | struct static_require_default; |
| 32 | |
| 33 | template <typename T, typename Property, typename = void> |
| 34 | struct static_require; |
| 35 | |
| 36 | } // namespace traits |
| 37 | namespace detail { |
| 38 | |
| 39 | struct no_static_require |
| 40 | { |
| 41 | static constexpr bool is_valid = false; |
| 42 | }; |
| 43 | |
| 44 | template <typename T, typename Property, typename = void> |
| 45 | struct static_require_trait : |
| 46 | conditional_t< |
| 47 | is_same<T, decay_t<T>>::value |
| 48 | && is_same<Property, decay_t<Property>>::value, |
| 49 | no_static_require, |
| 50 | traits::static_require< |
| 51 | decay_t<T>, |
| 52 | decay_t<Property>> |
| 53 | > |
| 54 | { |
| 55 | }; |
| 56 | |
| 57 | #if defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) |
| 58 | |
| 59 | template <typename T, typename Property> |
| 60 | struct static_require_trait<T, Property, |
| 61 | enable_if_t< |
| 62 | decay_t<Property>::value() == traits::static_query<T, Property>::value() |
| 63 | >> |
| 64 | { |
| 65 | static constexpr bool is_valid = true; |
| 66 | }; |
| 67 | |
| 68 | #else // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) |
| 69 | |
| 70 | false_type static_require_test(...); |
| 71 | |
| 72 | template <typename T, typename Property> |
| 73 | true_type static_require_test(T*, Property*, |
| 74 | enable_if_t< |
| 75 | Property::value() == traits::static_query<T, Property>::value() |
| 76 | >* = 0); |
| 77 | |
| 78 | template <typename T, typename Property> |
| 79 | struct has_static_require |
| 80 | { |
| 81 | static constexpr bool value = |
| 82 | decltype((static_require_test)( |
| 83 | static_cast<T*>(0), static_cast<Property*>(0)))::value; |
| 84 | }; |
| 85 | |
| 86 | template <typename T, typename Property> |
| 87 | struct static_require_trait<T, Property, |
| 88 | enable_if_t< |
| 89 | has_static_require<decay_t<T>, |
| 90 | decay_t<Property>>::value |
| 91 | >> |
| 92 | { |
| 93 | static constexpr bool is_valid = true; |
| 94 | }; |
| 95 | |
| 96 | #endif // defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) |
| 97 | |
| 98 | } // namespace detail |
| 99 | namespace traits { |
| 100 | |
| 101 | template <typename T, typename Property, typename> |
| 102 | struct static_require_default : detail::static_require_trait<T, Property> |
| 103 | { |
| 104 | }; |
| 105 | |
| 106 | template <typename T, typename Property, typename> |
| 107 | struct static_require : static_require_default<T, Property> |
| 108 | { |
| 109 | }; |
| 110 | |
| 111 | } // namespace traits |
| 112 | } // namespace asio |
| 113 | } // namespace boost |
| 114 | |
| 115 | #include <boost/asio/detail/pop_options.hpp> |
| 116 | |
| 117 | #endif // BOOST_ASIO_TRAITS_STATIC_REQUIRE_HPP |
| 118 | |