| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_UTILITY |
| 11 | #define _LIBCPP_UTILITY |
| 12 | |
| 13 | /* |
| 14 | utility synopsis |
| 15 | |
| 16 | #include <initializer_list> |
| 17 | |
| 18 | namespace std |
| 19 | { |
| 20 | |
| 21 | template <class T> |
| 22 | void |
| 23 | swap(T& a, T& b); |
| 24 | |
| 25 | namespace rel_ops |
| 26 | { |
| 27 | template<class T> bool operator!=(const T&, const T&); |
| 28 | template<class T> bool operator> (const T&, const T&); |
| 29 | template<class T> bool operator<=(const T&, const T&); |
| 30 | template<class T> bool operator>=(const T&, const T&); |
| 31 | } |
| 32 | |
| 33 | template<class T> |
| 34 | void |
| 35 | swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && |
| 36 | is_nothrow_move_assignable<T>::value); |
| 37 | |
| 38 | template <class T, size_t N> |
| 39 | void |
| 40 | swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); |
| 41 | |
| 42 | template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 |
| 43 | template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 |
| 44 | |
| 45 | template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 |
| 46 | |
| 47 | template <class T> |
| 48 | typename conditional |
| 49 | < |
| 50 | !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, |
| 51 | const T&, |
| 52 | T&& |
| 53 | >::type |
| 54 | move_if_noexcept(T& x) noexcept; // constexpr in C++14 |
| 55 | |
| 56 | template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17 |
| 57 | template <class T> void as_const(const T&&) = delete; // C++17 |
| 58 | |
| 59 | template <class T> typename add_rvalue_reference<T>::type declval() noexcept; |
| 60 | |
| 61 | template<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept; // C++20 |
| 62 | template<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20 |
| 63 | template<class T, class U> constexpr bool cmp_less(T t, U u) noexcept; // C++20 |
| 64 | template<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept; // C++20 |
| 65 | template<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20 |
| 66 | template<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20 |
| 67 | template<class R, class T> constexpr bool in_range(T t) noexcept; // C++20 |
| 68 | |
| 69 | template <class T1, class T2> |
| 70 | struct pair |
| 71 | { |
| 72 | typedef T1 first_type; |
| 73 | typedef T2 second_type; |
| 74 | |
| 75 | T1 first; |
| 76 | T2 second; |
| 77 | |
| 78 | pair(const pair&) = default; |
| 79 | pair(pair&&) = default; |
| 80 | explicit(see-below) constexpr pair(); |
| 81 | explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14 |
| 82 | template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&); // constexpr in C++14 |
| 83 | template <class U, class V> explicit(see-below) pair(const pair<U, V>& p); // constexpr in C++14 |
| 84 | template <class U, class V> explicit(see-below) pair(pair<U, V>&& p); // constexpr in C++14 |
| 85 | template <class... Args1, class... Args2> |
| 86 | pair(piecewise_construct_t, tuple<Args1...> first_args, |
| 87 | tuple<Args2...> second_args); // constexpr in C++20 |
| 88 | |
| 89 | template <class U, class V> pair& operator=(const pair<U, V>& p); // constexpr in C++20 |
| 90 | pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && |
| 91 | is_nothrow_move_assignable<T2>::value); // constexpr in C++20 |
| 92 | template <class U, class V> pair& operator=(pair<U, V>&& p); // constexpr in C++20 |
| 93 | |
| 94 | void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> && |
| 95 | is_nothrow_swappable_v<T2>); // constexpr in C++20 |
| 96 | }; |
| 97 | |
| 98 | template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual> |
| 99 | struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23 |
| 100 | |
| 101 | template<class T1, class T2, class U1, class U2> |
| 102 | struct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23 |
| 103 | |
| 104 | template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>; |
| 105 | |
| 106 | template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 |
| 107 | template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 |
| 108 | template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 |
| 109 | template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 |
| 110 | template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 |
| 111 | template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 |
| 112 | template <class T1, class T2> |
| 113 | constexpr common_comparison_type_t<synth-three-way-result<T1>, |
| 114 | synth-three-way-result<T2>> |
| 115 | operator<=>(const pair<T1,T2>&, const pair<T1,T2>&); // C++20 |
| 116 | |
| 117 | template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 |
| 118 | template <class T1, class T2> |
| 119 | void |
| 120 | swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 |
| 121 | |
| 122 | struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; |
| 123 | inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); |
| 124 | |
| 125 | template <class T> struct tuple_size; |
| 126 | template <size_t I, class T> struct tuple_element; |
| 127 | |
| 128 | template <class T1, class T2> struct tuple_size<pair<T1, T2> >; |
| 129 | template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; |
| 130 | template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; |
| 131 | |
| 132 | template<size_t I, class T1, class T2> |
| 133 | typename tuple_element<I, pair<T1, T2> >::type& |
| 134 | get(pair<T1, T2>&) noexcept; // constexpr in C++14 |
| 135 | |
| 136 | template<size_t I, class T1, class T2> |
| 137 | const typename tuple_element<I, pair<T1, T2> >::type& |
| 138 | get(const pair<T1, T2>&) noexcept; // constexpr in C++14 |
| 139 | |
| 140 | template<size_t I, class T1, class T2> |
| 141 | typename tuple_element<I, pair<T1, T2> >::type&& |
| 142 | get(pair<T1, T2>&&) noexcept; // constexpr in C++14 |
| 143 | |
| 144 | template<size_t I, class T1, class T2> |
| 145 | const typename tuple_element<I, pair<T1, T2> >::type&& |
| 146 | get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 |
| 147 | |
| 148 | template<class T1, class T2> |
| 149 | constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 |
| 150 | |
| 151 | template<class T1, class T2> |
| 152 | constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 |
| 153 | |
| 154 | template<class T1, class T2> |
| 155 | constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 |
| 156 | |
| 157 | template<class T1, class T2> |
| 158 | constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 |
| 159 | |
| 160 | template<class T1, class T2> |
| 161 | constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 |
| 162 | |
| 163 | template<class T1, class T2> |
| 164 | constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 |
| 165 | |
| 166 | template<class T1, class T2> |
| 167 | constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 |
| 168 | |
| 169 | template<class T1, class T2> |
| 170 | constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 |
| 171 | |
| 172 | // C++14 |
| 173 | |
| 174 | template<class T, T... I> |
| 175 | struct integer_sequence |
| 176 | { |
| 177 | typedef T value_type; |
| 178 | |
| 179 | static constexpr size_t size() noexcept; |
| 180 | }; |
| 181 | |
| 182 | template<size_t... I> |
| 183 | using index_sequence = integer_sequence<size_t, I...>; |
| 184 | |
| 185 | template<class T, T N> |
| 186 | using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; |
| 187 | template<size_t N> |
| 188 | using make_index_sequence = make_integer_sequence<size_t, N>; |
| 189 | |
| 190 | template<class... T> |
| 191 | using index_sequence_for = make_index_sequence<sizeof...(T)>; |
| 192 | |
| 193 | template<class T, class U=T> |
| 194 | constexpr T exchange(T& obj, U&& new_value) |
| 195 | noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23 |
| 196 | |
| 197 | // 20.2.7, in-place construction // C++17 |
| 198 | struct in_place_t { |
| 199 | explicit in_place_t() = default; |
| 200 | }; |
| 201 | inline constexpr in_place_t in_place{}; |
| 202 | template <class T> |
| 203 | struct in_place_type_t { |
| 204 | explicit in_place_type_t() = default; |
| 205 | }; |
| 206 | template <class T> |
| 207 | inline constexpr in_place_type_t<T> in_place_type{}; |
| 208 | template <size_t I> |
| 209 | struct in_place_index_t { |
| 210 | explicit in_place_index_t() = default; |
| 211 | }; |
| 212 | template <size_t I> |
| 213 | inline constexpr in_place_index_t<I> in_place_index{}; |
| 214 | |
| 215 | // [utility.underlying], to_underlying |
| 216 | template <class T> |
| 217 | constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b |
| 218 | |
| 219 | } // std |
| 220 | |
| 221 | */ |
| 222 | |
| 223 | #include <__assert> // all public C++ headers provide the assertion handler |
| 224 | #include <__config> |
| 225 | #include <__tuple> |
| 226 | #include <__utility/as_const.h> |
| 227 | #include <__utility/auto_cast.h> |
| 228 | #include <__utility/cmp.h> |
| 229 | #include <__utility/declval.h> |
| 230 | #include <__utility/exchange.h> |
| 231 | #include <__utility/forward.h> |
| 232 | #include <__utility/in_place.h> |
| 233 | #include <__utility/integer_sequence.h> |
| 234 | #include <__utility/move.h> |
| 235 | #include <__utility/pair.h> |
| 236 | #include <__utility/piecewise_construct.h> |
| 237 | #include <__utility/priority_tag.h> |
| 238 | #include <__utility/rel_ops.h> |
| 239 | #include <__utility/swap.h> |
| 240 | #include <__utility/to_underlying.h> |
| 241 | #include <__utility/transaction.h> |
| 242 | #include <__utility/unreachable.h> |
| 243 | #include <type_traits> |
| 244 | #include <version> |
| 245 | |
| 246 | #ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES |
| 247 | # include <iosfwd> |
| 248 | #endif |
| 249 | |
| 250 | // standard-mandated includes |
| 251 | #include <compare> |
| 252 | #include <initializer_list> |
| 253 | |
| 254 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 255 | # pragma GCC system_header |
| 256 | #endif |
| 257 | |
| 258 | #endif // _LIBCPP_UTILITY |
| 259 | |