]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/libcxx/include/utility
OpenSSL: Vendor import of OpenSSL 3.0.13
[FreeBSD/FreeBSD.git] / contrib / llvm-project / libcxx / include / utility
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 <typename T>
46 [[nodiscard]] constexpr
47 auto forward_like(auto&& x) noexcept -> see below;                               // since C++23
48
49 template <class T> typename remove_reference<T>::type&& move(T&&) noexcept;      // constexpr in C++14
50
51 template <class T>
52     typename conditional
53     <
54         !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
55         const T&,
56         T&&
57     >::type
58     move_if_noexcept(T& x) noexcept; // constexpr in C++14
59
60 template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept;      // C++17
61 template <class T>                      void as_const(const T&&) = delete; // C++17
62
63 template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
64
65 template<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept;         // C++20
66 template<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept;     // C++20
67 template<class T, class U> constexpr bool cmp_less(T t, U u) noexcept;          // C++20
68 template<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept;       // C++20
69 template<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept;    // C++20
70 template<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20
71 template<class R, class T> constexpr bool in_range(T t) noexcept;               // C++20
72
73 template <class T1, class T2>
74 struct pair
75 {
76     typedef T1 first_type;
77     typedef T2 second_type;
78
79     T1 first;
80     T2 second;
81
82     pair(const pair&) = default;
83     pair(pair&&) = default;
84     explicit(see-below) constexpr pair();
85     explicit(see-below) pair(const T1& x, const T2& y);                          // constexpr in C++14
86     template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&);    // constexpr in C++14
87     template <class U, class V> constexpr explicit(see-below) pair(pair<U, V>&); // since C++23
88     template <class U, class V> explicit(see-below) pair(const pair<U, V>& p);   // constexpr in C++14
89     template <class U, class V> explicit(see-below) pair(pair<U, V>&& p);        // constexpr in C++14
90     template <class U, class V>
91     constexpr explicit(see-below) pair(const pair<U, V>&&);                      // since C++23
92     template <pair-like P> constexpr explicit(see-below) pair(P&&);              // since C++23
93     template <class... Args1, class... Args2>
94         pair(piecewise_construct_t, tuple<Args1...> first_args,                  // constexpr in C++20
95                                     tuple<Args2...> second_args);
96
97     constexpr const pair& operator=(const pair& p) const;                        // since C++23
98     template <class U, class V> pair& operator=(const pair<U, V>& p);            // constexpr in C++20
99     template <class U, class V>
100     constexpr const pair& operator=(const pair<U, V>& p) const;                  // since C++23
101     pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
102                                        is_nothrow_move_assignable<T2>::value);   // constexpr in C++20
103     constexpr const pair& operator=(pair&& p) const;                             // since C++23
104     template <class U, class V> pair& operator=(pair<U, V>&& p);                 // constexpr in C++20
105     template <class U, class V>
106     constexpr const pair& operator=(pair<U, V>&& p) const;                       // since C++23
107     template <pair-like P> constexpr pair& operator=(P&&);                       // since C++23
108     template <pair-like P> constexpr const pair& operator=(P&&) const;           // since C++23
109
110     void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
111                                 is_nothrow_swappable_v<T2>);                     // constexpr in C++20
112     constexpr void swap(const pair& p) const noexcept(see below);                // since C++23
113 };
114
115 template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual>
116 struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>;         // since C++23
117
118 template<class T1, class T2, class U1, class U2>
119 struct common_type<pair<T1, T2>, pair<U1, U2>>;                                  // since C++23
120
121 template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
122
123 template <class T1, class T2, class U1, class U2>
124 bool operator==(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14
125 template <class T1, class T2, class U1, class U2>
126 bool operator!=(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20
127 template <class T1, class T2, class U1, class U2>
128 bool operator< (const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20
129 template <class T1, class T2, class U1, class U2>
130 bool operator> (const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20
131 template <class T1, class T2, class U1, class U2>
132 bool operator>=(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20
133 template <class T1, class T2, class U1, class U2>
134 bool operator<=(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20
135 template <class T1, class T2, class U1, class U2>
136   constexpr common_comparison_type_t<synth-three-way-result<T1,U1>,
137                                      synth-three-way-result<T2,U2>>
138     operator<=>(const pair<T1,T2>&, const pair<U1,U2>&);                         // C++20
139
140 template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);                // constexpr in C++14
141 template <class T1, class T2>
142 void
143 swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));            // constexpr in C++20
144
145 template<class T1, class T2>                                                     // since C++23
146 constexpr void swap(const pair<T1, T2>& x, const pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
147
148 struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
149 inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
150
151 template <class T> struct tuple_size;
152 template <size_t I, class T> struct tuple_element;
153
154 template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
155 template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
156 template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
157
158 template<size_t I, class T1, class T2>
159     typename tuple_element<I, pair<T1, T2> >::type&
160     get(pair<T1, T2>&) noexcept; // constexpr in C++14
161
162 template<size_t I, class T1, class T2>
163     const typename tuple_element<I, pair<T1, T2> >::type&
164     get(const pair<T1, T2>&) noexcept; // constexpr in C++14
165
166 template<size_t I, class T1, class T2>
167     typename tuple_element<I, pair<T1, T2> >::type&&
168     get(pair<T1, T2>&&) noexcept; // constexpr in C++14
169
170 template<size_t I, class T1, class T2>
171     const typename tuple_element<I, pair<T1, T2> >::type&&
172     get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
173
174 template<class T1, class T2>
175     constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
176
177 template<class T1, class T2>
178     constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
179
180 template<class T1, class T2>
181     constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
182
183 template<class T1, class T2>
184     constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
185
186 template<class T1, class T2>
187     constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
188
189 template<class T1, class T2>
190     constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
191
192 template<class T1, class T2>
193     constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
194
195 template<class T1, class T2>
196     constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
197
198 // C++14
199
200 template<class T, T... I>
201 struct integer_sequence
202 {
203     typedef T value_type;
204
205     static constexpr size_t size() noexcept;
206 };
207
208 template<size_t... I>
209   using index_sequence = integer_sequence<size_t, I...>;
210
211 template<class T, T N>
212   using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
213 template<size_t N>
214   using make_index_sequence = make_integer_sequence<size_t, N>;
215
216 template<class... T>
217   using index_sequence_for = make_index_sequence<sizeof...(T)>;
218
219 template<class T, class U=T>
220     constexpr T exchange(T& obj, U&& new_value)                                 // constexpr in C++17, noexcept in C++23
221       noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value);
222
223 // 20.2.7, in-place construction // C++17
224 struct in_place_t {
225   explicit in_place_t() = default;
226 };
227 inline constexpr in_place_t in_place{};
228 template <class T>
229   struct in_place_type_t {
230     explicit in_place_type_t() = default;
231   };
232 template <class T>
233   inline constexpr in_place_type_t<T> in_place_type{};
234 template <size_t I>
235   struct in_place_index_t {
236     explicit in_place_index_t() = default;
237   };
238 template <size_t I>
239   inline constexpr in_place_index_t<I> in_place_index{};
240
241 // [utility.underlying], to_underlying
242 template <class T>
243     constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++23
244
245 }  // std
246
247 */
248
249 #include <__assert> // all public C++ headers provide the assertion handler
250 #include <__config>
251 #include <__utility/as_const.h>
252 #include <__utility/auto_cast.h>
253 #include <__utility/cmp.h>
254 #include <__utility/declval.h>
255 #include <__utility/exception_guard.h>
256 #include <__utility/exchange.h>
257 #include <__utility/forward.h>
258 #include <__utility/forward_like.h>
259 #include <__utility/in_place.h>
260 #include <__utility/integer_sequence.h>
261 #include <__utility/move.h>
262 #include <__utility/pair.h>
263 #include <__utility/piecewise_construct.h>
264 #include <__utility/priority_tag.h>
265 #include <__utility/rel_ops.h>
266 #include <__utility/swap.h>
267 #include <__utility/to_underlying.h>
268 #include <__utility/unreachable.h>
269 #include <version>
270
271 // standard-mandated includes
272
273 // [utility.syn]
274 #include <compare>
275 #include <initializer_list>
276
277 // [tuple.helper]
278 #include <__tuple/tuple_element.h>
279 #include <__tuple/tuple_size.h>
280
281 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
282 #  pragma GCC system_header
283 #endif
284
285 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
286 #  include <cstdlib>
287 #  include <iosfwd>
288 #  include <type_traits>
289 #endif
290
291 #endif // _LIBCPP_UTILITY