2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_UTILITY
11 #define _LIBCPP_UTILITY
16 #include <initializer_list>
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&);
35 swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
36 is_nothrow_move_assignable<T>::value);
38 template <class T, size_t N>
40 swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
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
45 template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
50 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
54 move_if_noexcept(T& x) noexcept; // constexpr in C++14
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
59 template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
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
69 template <class T1, class T2>
72 typedef T1 first_type;
73 typedef T2 second_type;
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
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
94 void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
95 is_nothrow_swappable_v<T2>); // constexpr in C++20
98 template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
100 template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
101 template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
102 template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
103 template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
104 template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
105 template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
106 template <class T1, class T2>
107 constexpr common_comparison_type_t<synth-three-way-result<T1>,
108 synth-three-way-result<T2>>
109 operator<=>(const pair<T1,T2>&, const pair<T1,T2>&); // C++20
111 template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
112 template <class T1, class T2>
114 swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
116 struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
117 inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
119 template <class T> struct tuple_size;
120 template <size_t I, class T> struct tuple_element;
122 template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
123 template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
124 template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
126 template<size_t I, class T1, class T2>
127 typename tuple_element<I, pair<T1, T2> >::type&
128 get(pair<T1, T2>&) noexcept; // constexpr in C++14
130 template<size_t I, class T1, class T2>
131 const typename tuple_element<I, pair<T1, T2> >::type&
132 get(const pair<T1, T2>&) noexcept; // constexpr in C++14
134 template<size_t I, class T1, class T2>
135 typename tuple_element<I, pair<T1, T2> >::type&&
136 get(pair<T1, T2>&&) noexcept; // constexpr in C++14
138 template<size_t I, class T1, class T2>
139 const typename tuple_element<I, pair<T1, T2> >::type&&
140 get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
142 template<class T1, class T2>
143 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
145 template<class T1, class T2>
146 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
148 template<class T1, class T2>
149 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
151 template<class T1, class T2>
152 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
154 template<class T1, class T2>
155 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
157 template<class T1, class T2>
158 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
160 template<class T1, class T2>
161 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
163 template<class T1, class T2>
164 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
168 template<class T, T... I>
169 struct integer_sequence
171 typedef T value_type;
173 static constexpr size_t size() noexcept;
176 template<size_t... I>
177 using index_sequence = integer_sequence<size_t, I...>;
179 template<class T, T N>
180 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
182 using make_index_sequence = make_integer_sequence<size_t, N>;
185 using index_sequence_for = make_index_sequence<sizeof...(T)>;
187 template<class T, class U=T>
188 constexpr T exchange(T& obj, U&& new_value)
189 noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23
191 // 20.2.7, in-place construction // C++17
193 explicit in_place_t() = default;
195 inline constexpr in_place_t in_place{};
197 struct in_place_type_t {
198 explicit in_place_type_t() = default;
201 inline constexpr in_place_type_t<T> in_place_type{};
203 struct in_place_index_t {
204 explicit in_place_index_t() = default;
207 inline constexpr in_place_index_t<I> in_place_index{};
209 // [utility.underlying], to_underlying
211 constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b
220 #include <__utility/as_const.h>
221 #include <__utility/auto_cast.h>
222 #include <__utility/cmp.h>
223 #include <__utility/declval.h>
224 #include <__utility/exchange.h>
225 #include <__utility/forward.h>
226 #include <__utility/in_place.h>
227 #include <__utility/integer_sequence.h>
228 #include <__utility/move.h>
229 #include <__utility/pair.h>
230 #include <__utility/piecewise_construct.h>
231 #include <__utility/priority_tag.h>
232 #include <__utility/rel_ops.h>
233 #include <__utility/swap.h>
234 #include <__utility/to_underlying.h>
235 #include <__utility/transaction.h>
237 #include <initializer_list>
240 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241 #pragma GCC system_header
244 #endif // _LIBCPP_UTILITY