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 18namespace std 19{ 20 21template <class T> 22 void 23 swap(T& a, T& b); 24 25namespace 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 33template<class T> 34void 35swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && 36 is_nothrow_move_assignable<T>::value); 37 38template <class T, size_t N> 39void 40swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); 41 42template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 43template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 44 45template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 46 47template <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 56template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17 57template <class T> void as_const(const T&&) = delete; // C++17 58 59template <class T> typename add_rvalue_reference<T>::type declval() noexcept; 60 61template<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept; // C++20 62template<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20 63template<class T, class U> constexpr bool cmp_less(T t, U u) noexcept; // C++20 64template<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept; // C++20 65template<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20 66template<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20 67template<class R, class T> constexpr bool in_range(T t) noexcept; // C++20 68 69template <class T1, class T2> 70struct 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 98template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual> 99struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23 100 101template<class T1, class T2, class U1, class U2> 102struct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23 103 104template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>; 105 106template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 107template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 108template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 109template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 110template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 111template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 112template <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 117template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 118template <class T1, class T2> 119void 120swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 121 122struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; 123inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 124 125template <class T> struct tuple_size; 126template <size_t I, class T> struct tuple_element; 127 128template <class T1, class T2> struct tuple_size<pair<T1, T2> >; 129template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; 130template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; 131 132template<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 136template<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 140template<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 144template<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 148template<class T1, class T2> 149 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 150 151template<class T1, class T2> 152 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 153 154template<class T1, class T2> 155 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 156 157template<class T1, class T2> 158 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 159 160template<class T1, class T2> 161 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 162 163template<class T1, class T2> 164 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 165 166template<class T1, class T2> 167 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 168 169template<class T1, class T2> 170 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 171 172// C++14 173 174template<class T, T... I> 175struct integer_sequence 176{ 177 typedef T value_type; 178 179 static constexpr size_t size() noexcept; 180}; 181 182template<size_t... I> 183 using index_sequence = integer_sequence<size_t, I...>; 184 185template<class T, T N> 186 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; 187template<size_t N> 188 using make_index_sequence = make_integer_sequence<size_t, N>; 189 190template<class... T> 191 using index_sequence_for = make_index_sequence<sizeof...(T)>; 192 193template<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 198struct in_place_t { 199 explicit in_place_t() = default; 200}; 201inline constexpr in_place_t in_place{}; 202template <class T> 203 struct in_place_type_t { 204 explicit in_place_type_t() = default; 205 }; 206template <class T> 207 inline constexpr in_place_type_t<T> in_place_type{}; 208template <size_t I> 209 struct in_place_index_t { 210 explicit in_place_index_t() = default; 211 }; 212template <size_t I> 213 inline constexpr in_place_index_t<I> in_place_index{}; 214 215// [utility.underlying], to_underlying 216template <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