| 1 | // |
| 2 | // detail/type_traits.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_DETAIL_TYPE_TRAITS_HPP |
| 12 | #define BOOST_ASIO_DETAIL_TYPE_TRAITS_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 <type_traits> |
| 20 | |
| 21 | namespace boost { |
| 22 | namespace asio { |
| 23 | |
| 24 | using std::add_const; |
| 25 | |
| 26 | template <typename T> |
| 27 | using add_const_t = typename std::add_const<T>::type; |
| 28 | |
| 29 | using std::add_lvalue_reference; |
| 30 | |
| 31 | template <typename T> |
| 32 | using add_lvalue_reference_t = typename std::add_lvalue_reference<T>::type; |
| 33 | |
| 34 | template <std::size_t N, std::size_t A> |
| 35 | struct aligned_storage |
| 36 | { |
| 37 | struct type |
| 38 | { |
| 39 | alignas(A) unsigned char data[N]; |
| 40 | }; |
| 41 | }; |
| 42 | |
| 43 | template <std::size_t N, std::size_t A> |
| 44 | using aligned_storage_t = typename aligned_storage<N, A>::type; |
| 45 | |
| 46 | using std::alignment_of; |
| 47 | |
| 48 | using std::conditional; |
| 49 | |
| 50 | template <bool C, typename T, typename U> |
| 51 | using conditional_t = typename std::conditional<C, T, U>::type; |
| 52 | |
| 53 | using std::decay; |
| 54 | |
| 55 | template <typename T> |
| 56 | using decay_t = typename std::decay<T>::type; |
| 57 | |
| 58 | using std::declval; |
| 59 | |
| 60 | using std::enable_if; |
| 61 | |
| 62 | template <bool C, typename T = void> |
| 63 | using enable_if_t = typename std::enable_if<C, T>::type; |
| 64 | |
| 65 | using std::false_type; |
| 66 | |
| 67 | using std::integral_constant; |
| 68 | |
| 69 | using std::is_base_of; |
| 70 | |
| 71 | using std::is_class; |
| 72 | |
| 73 | using std::is_const; |
| 74 | |
| 75 | using std::is_constructible; |
| 76 | |
| 77 | using std::is_convertible; |
| 78 | |
| 79 | using std::is_copy_constructible; |
| 80 | |
| 81 | using std::is_destructible; |
| 82 | |
| 83 | using std::is_function; |
| 84 | |
| 85 | using std::is_move_constructible; |
| 86 | |
| 87 | using std::is_nothrow_copy_constructible; |
| 88 | |
| 89 | using std::is_nothrow_destructible; |
| 90 | |
| 91 | using std::is_object; |
| 92 | |
| 93 | using std::is_pointer; |
| 94 | |
| 95 | using std::is_reference; |
| 96 | |
| 97 | using std::is_same; |
| 98 | |
| 99 | using std::is_scalar; |
| 100 | |
| 101 | using std::remove_cv; |
| 102 | |
| 103 | template <typename T> |
| 104 | using remove_cv_t = typename std::remove_cv<T>::type; |
| 105 | |
| 106 | template <typename T> |
| 107 | struct remove_cvref : |
| 108 | std::remove_cv<typename std::remove_reference<T>::type> {}; |
| 109 | |
| 110 | template <typename T> |
| 111 | using remove_cvref_t = typename remove_cvref<T>::type; |
| 112 | |
| 113 | using std::remove_pointer; |
| 114 | |
| 115 | template <typename T> |
| 116 | using remove_pointer_t = typename std::remove_pointer<T>::type; |
| 117 | |
| 118 | using std::remove_reference; |
| 119 | |
| 120 | template <typename T> |
| 121 | using remove_reference_t = typename std::remove_reference<T>::type; |
| 122 | |
| 123 | #if defined(BOOST_ASIO_HAS_STD_INVOKE_RESULT) |
| 124 | |
| 125 | template <typename> struct result_of; |
| 126 | |
| 127 | template <typename F, typename... Args> |
| 128 | struct result_of<F(Args...)> : std::invoke_result<F, Args...> {}; |
| 129 | |
| 130 | template <typename T> |
| 131 | using result_of_t = typename result_of<T>::type; |
| 132 | |
| 133 | #else // defined(BOOST_ASIO_HAS_STD_INVOKE_RESULT) |
| 134 | |
| 135 | using std::result_of; |
| 136 | |
| 137 | template <typename T> |
| 138 | using result_of_t = typename std::result_of<T>::type; |
| 139 | |
| 140 | #endif // defined(BOOST_ASIO_HAS_STD_INVOKE_RESULT) |
| 141 | |
| 142 | using std::true_type; |
| 143 | |
| 144 | template <typename> struct void_type |
| 145 | { |
| 146 | typedef void type; |
| 147 | }; |
| 148 | |
| 149 | template <typename T> |
| 150 | using void_t = typename void_type<T>::type; |
| 151 | |
| 152 | template <typename...> struct conjunction : true_type {}; |
| 153 | |
| 154 | template <typename T> struct conjunction<T> : T {}; |
| 155 | |
| 156 | template <typename Head, typename... Tail> |
| 157 | struct conjunction<Head, Tail...> : |
| 158 | conditional_t<Head::value, conjunction<Tail...>, Head> {}; |
| 159 | |
| 160 | struct defaulted_constraint |
| 161 | { |
| 162 | constexpr defaulted_constraint() {} |
| 163 | }; |
| 164 | |
| 165 | template <bool Condition, typename Type = int> |
| 166 | struct constraint : std::enable_if<Condition, Type> {}; |
| 167 | |
| 168 | template <bool Condition, typename Type = int> |
| 169 | using constraint_t = typename constraint<Condition, Type>::type; |
| 170 | |
| 171 | template <typename T> |
| 172 | struct type_identity { typedef T type; }; |
| 173 | |
| 174 | template <typename T> |
| 175 | using type_identity_t = typename type_identity<T>::type; |
| 176 | |
| 177 | } // namespace asio |
| 178 | } // namespace boost |
| 179 | |
| 180 | #endif // BOOST_ASIO_DETAIL_TYPE_TRAITS_HPP |
| 181 | |