1// -*- C++ -*- 2//===-------------------------- utility -----------------------------------===// 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, class V> explicit(see-below) pair(U&& x, V&& y); // 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> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 99template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 100template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 101template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 102template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 103template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 104 105template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 106template <class T1, class T2> 107void 108swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 109 110struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; 111inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 112 113template <class T> struct tuple_size; 114template <size_t I, class T> struct tuple_element; 115 116template <class T1, class T2> struct tuple_size<pair<T1, T2> >; 117template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; 118template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; 119 120template<size_t I, class T1, class T2> 121 typename tuple_element<I, pair<T1, T2> >::type& 122 get(pair<T1, T2>&) noexcept; // constexpr in C++14 123 124template<size_t I, class T1, class T2> 125 const typename tuple_element<I, pair<T1, T2> >::type& 126 get(const pair<T1, T2>&) noexcept; // constexpr in C++14 127 128template<size_t I, class T1, class T2> 129 typename tuple_element<I, pair<T1, T2> >::type&& 130 get(pair<T1, T2>&&) noexcept; // constexpr in C++14 131 132template<size_t I, class T1, class T2> 133 const typename tuple_element<I, pair<T1, T2> >::type&& 134 get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 135 136template<class T1, class T2> 137 constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 138 139template<class T1, class T2> 140 constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 141 142template<class T1, class T2> 143 constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 144 145template<class T1, class T2> 146 constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 147 148template<class T1, class T2> 149 constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 150 151template<class T1, class T2> 152 constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 153 154template<class T1, class T2> 155 constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 156 157template<class T1, class T2> 158 constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 159 160// C++14 161 162template<class T, T... I> 163struct integer_sequence 164{ 165 typedef T value_type; 166 167 static constexpr size_t size() noexcept; 168}; 169 170template<size_t... I> 171 using index_sequence = integer_sequence<size_t, I...>; 172 173template<class T, T N> 174 using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; 175template<size_t N> 176 using make_index_sequence = make_integer_sequence<size_t, N>; 177 178template<class... T> 179 using index_sequence_for = make_index_sequence<sizeof...(T)>; 180 181template<class T, class U=T> 182 T exchange(T& obj, U&& new_value); 183 184// 20.2.7, in-place construction // C++17 185struct in_place_t { 186 explicit in_place_t() = default; 187}; 188inline constexpr in_place_t in_place{}; 189template <class T> 190 struct in_place_type_t { 191 explicit in_place_type_t() = default; 192 }; 193template <class T> 194 inline constexpr in_place_type_t<T> in_place_type{}; 195template <size_t I> 196 struct in_place_index_t { 197 explicit in_place_index_t() = default; 198 }; 199template <size_t I> 200 inline constexpr in_place_index_t<I> in_place_index{}; 201 202// [utility.underlying], to_underlying 203template <class T> 204 constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b 205 206} // std 207 208*/ 209 210#include <__config> 211#include <__debug> 212#include <__tuple> 213#include <__utility/as_const.h> 214#include <__utility/cmp.h> 215#include <__utility/declval.h> 216#include <__utility/exchange.h> 217#include <__utility/forward.h> 218#include <__utility/in_place.h> 219#include <__utility/integer_sequence.h> 220#include <__utility/move.h> 221#include <__utility/pair.h> 222#include <__utility/piecewise_construct.h> 223#include <__utility/rel_ops.h> 224#include <__utility/swap.h> 225#include <__utility/to_underlying.h> 226#include <compare> 227#include <initializer_list> 228#include <version> 229 230#endif // _LIBCPP_UTILITY 231