1 | // |
2 | // traits/static_query.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_QUERY_HPP |
12 | #define BOOST_ASIO_TRAITS_STATIC_QUERY_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_VARIABLE_TEMPLATES) \ |
22 | && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) |
23 | # define BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT 1 |
24 | #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES) |
25 | // && defined(BOOST_ASIO_HAS_WORKING_EXPRESSION_SFINAE) |
26 | |
27 | #include <boost/asio/detail/push_options.hpp> |
28 | |
29 | namespace boost { |
30 | namespace asio { |
31 | namespace traits { |
32 | |
33 | template <typename T, typename Property, typename = void> |
34 | struct static_query_default; |
35 | |
36 | template <typename T, typename Property, typename = void> |
37 | struct static_query; |
38 | |
39 | } // namespace traits |
40 | namespace detail { |
41 | |
42 | struct no_static_query |
43 | { |
44 | static constexpr bool is_valid = false; |
45 | static constexpr bool is_noexcept = false; |
46 | }; |
47 | |
48 | template <typename T, typename Property, typename = void> |
49 | struct static_query_trait : |
50 | conditional_t< |
51 | is_same<T, decay_t<T>>::value |
52 | && is_same<Property, decay_t<Property>>::value, |
53 | no_static_query, |
54 | traits::static_query< |
55 | decay_t<T>, |
56 | decay_t<Property>> |
57 | > |
58 | { |
59 | }; |
60 | |
61 | #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) |
62 | |
63 | template <typename T, typename Property> |
64 | struct static_query_trait<T, Property, |
65 | void_t< |
66 | decltype(decay_t<Property>::template static_query_v<T>) |
67 | >> |
68 | { |
69 | static constexpr bool is_valid = true; |
70 | |
71 | using result_type = decltype( |
72 | decay_t<Property>::template static_query_v<T>); |
73 | |
74 | static constexpr bool is_noexcept = |
75 | noexcept(decay_t<Property>::template static_query_v<T>); |
76 | |
77 | static constexpr result_type value() noexcept(is_noexcept) |
78 | { |
79 | return decay_t<Property>::template static_query_v<T>; |
80 | } |
81 | }; |
82 | |
83 | #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) |
84 | |
85 | } // namespace detail |
86 | namespace traits { |
87 | |
88 | template <typename T, typename Property, typename> |
89 | struct static_query_default : detail::static_query_trait<T, Property> |
90 | { |
91 | }; |
92 | |
93 | template <typename T, typename Property, typename> |
94 | struct static_query : static_query_default<T, Property> |
95 | { |
96 | }; |
97 | |
98 | } // namespace traits |
99 | } // namespace asio |
100 | } // namespace boost |
101 | |
102 | #include <boost/asio/detail/pop_options.hpp> |
103 | |
104 | #endif // BOOST_ASIO_TRAITS_STATIC_QUERY_HPP |
105 | |