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