10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_UTILITY 110b57cec5SDimitry Andric#define _LIBCPP_UTILITY 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric utility synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric#include <initializer_list> 170b57cec5SDimitry Andric 180b57cec5SDimitry Andricnamespace std 190b57cec5SDimitry Andric{ 200b57cec5SDimitry Andric 210b57cec5SDimitry Andrictemplate <class T> 220b57cec5SDimitry Andric void 230b57cec5SDimitry Andric swap(T& a, T& b); 240b57cec5SDimitry Andric 250b57cec5SDimitry Andricnamespace rel_ops 260b57cec5SDimitry Andric{ 270b57cec5SDimitry Andric template<class T> bool operator!=(const T&, const T&); 280b57cec5SDimitry Andric template<class T> bool operator> (const T&, const T&); 290b57cec5SDimitry Andric template<class T> bool operator<=(const T&, const T&); 300b57cec5SDimitry Andric template<class T> bool operator>=(const T&, const T&); 310b57cec5SDimitry Andric} 320b57cec5SDimitry Andric 330b57cec5SDimitry Andrictemplate<class T> 340b57cec5SDimitry Andricvoid 350b57cec5SDimitry Andricswap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && 360b57cec5SDimitry Andric is_nothrow_move_assignable<T>::value); 370b57cec5SDimitry Andric 380b57cec5SDimitry Andrictemplate <class T, size_t N> 390b57cec5SDimitry Andricvoid 400b57cec5SDimitry Andricswap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); 410b57cec5SDimitry Andric 420b57cec5SDimitry Andrictemplate <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 430b57cec5SDimitry Andrictemplate <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 440b57cec5SDimitry Andric 45*bdd1243dSDimitry Andrictemplate <typename T> 46*bdd1243dSDimitry Andric[[nodiscard]] constexpr 47*bdd1243dSDimitry Andricauto forward_like(auto&& x) noexcept -> see below; // since C++23 48*bdd1243dSDimitry Andric 490b57cec5SDimitry Andrictemplate <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 500b57cec5SDimitry Andric 510b57cec5SDimitry Andrictemplate <class T> 520b57cec5SDimitry Andric typename conditional 530b57cec5SDimitry Andric < 540b57cec5SDimitry Andric !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, 550b57cec5SDimitry Andric const T&, 560b57cec5SDimitry Andric T&& 570b57cec5SDimitry Andric >::type 580b57cec5SDimitry Andric move_if_noexcept(T& x) noexcept; // constexpr in C++14 590b57cec5SDimitry Andric 600b57cec5SDimitry Andrictemplate <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17 610b57cec5SDimitry Andrictemplate <class T> void as_const(const T&&) = delete; // C++17 620b57cec5SDimitry Andric 630b57cec5SDimitry Andrictemplate <class T> typename add_rvalue_reference<T>::type declval() noexcept; 640b57cec5SDimitry Andric 65fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept; // C++20 66fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20 67fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_less(T t, U u) noexcept; // C++20 68fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept; // C++20 69fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20 70fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20 71fe6060f1SDimitry Andrictemplate<class R, class T> constexpr bool in_range(T t) noexcept; // C++20 72fe6060f1SDimitry Andric 730b57cec5SDimitry Andrictemplate <class T1, class T2> 740b57cec5SDimitry Andricstruct pair 750b57cec5SDimitry Andric{ 760b57cec5SDimitry Andric typedef T1 first_type; 770b57cec5SDimitry Andric typedef T2 second_type; 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric T1 first; 800b57cec5SDimitry Andric T2 second; 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric pair(const pair&) = default; 830b57cec5SDimitry Andric pair(pair&&) = default; 84e40139ffSDimitry Andric explicit(see-below) constexpr pair(); 85e40139ffSDimitry Andric explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14 86349cc55cSDimitry Andric template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&); // constexpr in C++14 87*bdd1243dSDimitry Andric template <class U, class V> constexpr explicit(see below) pair(pair<U, V>&); // since C++23 88e40139ffSDimitry Andric template <class U, class V> explicit(see-below) pair(const pair<U, V>& p); // constexpr in C++14 89e40139ffSDimitry Andric template <class U, class V> explicit(see-below) pair(pair<U, V>&& p); // constexpr in C++14 90*bdd1243dSDimitry Andric template <class U, class V> 91*bdd1243dSDimitry Andric constexpr explicit(see below) pair(const pair<U, V>&&); // since C++23 920b57cec5SDimitry Andric template <class... Args1, class... Args2> 930b57cec5SDimitry Andric pair(piecewise_construct_t, tuple<Args1...> first_args, 94fe6060f1SDimitry Andric tuple<Args2...> second_args); // constexpr in C++20 950b57cec5SDimitry Andric 96*bdd1243dSDimitry Andric constexpr const pair& operator=(const pair& p) const; // since C++23 97fe6060f1SDimitry Andric template <class U, class V> pair& operator=(const pair<U, V>& p); // constexpr in C++20 98*bdd1243dSDimitry Andric template <class U, class V> 99*bdd1243dSDimitry Andric constexpr const pair& operator=(const pair<U, V>& p) const; // since C++23 1000b57cec5SDimitry Andric pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && 101fe6060f1SDimitry Andric is_nothrow_move_assignable<T2>::value); // constexpr in C++20 102*bdd1243dSDimitry Andric constexpr const pair& operator=(pair&& p) const; // since C++23 103fe6060f1SDimitry Andric template <class U, class V> pair& operator=(pair<U, V>&& p); // constexpr in C++20 104*bdd1243dSDimitry Andric template <class U, class V> 105*bdd1243dSDimitry Andric constexpr const pair& operator=(pair<U, V>&& p) const; // since C++23 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> && 108fe6060f1SDimitry Andric is_nothrow_swappable_v<T2>); // constexpr in C++20 109*bdd1243dSDimitry Andric constexpr void swap(const pair& p) const noexcept(see below); // since C++23 1100b57cec5SDimitry Andric}; 1110b57cec5SDimitry Andric 11281ad6265SDimitry Andrictemplate<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual> 11381ad6265SDimitry Andricstruct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23 11481ad6265SDimitry Andric 11581ad6265SDimitry Andrictemplate<class T1, class T2, class U1, class U2> 11681ad6265SDimitry Andricstruct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23 11781ad6265SDimitry Andric 118349cc55cSDimitry Andrictemplate<class T1, class T2> pair(T1, T2) -> pair<T1, T2>; 119349cc55cSDimitry Andric 1200b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 121349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 122349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 123349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 124349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 125349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20 126349cc55cSDimitry Andrictemplate <class T1, class T2> 127349cc55cSDimitry Andric constexpr common_comparison_type_t<synth-three-way-result<T1>, 128349cc55cSDimitry Andric synth-three-way-result<T2>> 129349cc55cSDimitry Andric operator<=>(const pair<T1,T2>&, const pair<T1,T2>&); // C++20 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andrictemplate <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 1320b57cec5SDimitry Andrictemplate <class T1, class T2> 1330b57cec5SDimitry Andricvoid 134fe6060f1SDimitry Andricswap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 1350b57cec5SDimitry Andric 136*bdd1243dSDimitry Andrictemplate<class T1, class T2> 137*bdd1243dSDimitry Andricconstexpr void swap(const pair<T1, T2>& x, const pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // since C++23 138*bdd1243dSDimitry Andric 139e40139ffSDimitry Andricstruct piecewise_construct_t { explicit piecewise_construct_t() = default; }; 1400b57cec5SDimitry Andricinline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andrictemplate <class T> struct tuple_size; 1430b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; 1440b57cec5SDimitry Andric 1450b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_size<pair<T1, T2> >; 1460b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; 1470b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1500b57cec5SDimitry Andric typename tuple_element<I, pair<T1, T2> >::type& 1510b57cec5SDimitry Andric get(pair<T1, T2>&) noexcept; // constexpr in C++14 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1540b57cec5SDimitry Andric const typename tuple_element<I, pair<T1, T2> >::type& 1550b57cec5SDimitry Andric get(const pair<T1, T2>&) noexcept; // constexpr in C++14 1560b57cec5SDimitry Andric 1570b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1580b57cec5SDimitry Andric typename tuple_element<I, pair<T1, T2> >::type&& 1590b57cec5SDimitry Andric get(pair<T1, T2>&&) noexcept; // constexpr in C++14 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1620b57cec5SDimitry Andric const typename tuple_element<I, pair<T1, T2> >::type&& 1630b57cec5SDimitry Andric get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andrictemplate<class T1, class T2> 1660b57cec5SDimitry Andric constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 1670b57cec5SDimitry Andric 1680b57cec5SDimitry Andrictemplate<class T1, class T2> 1690b57cec5SDimitry Andric constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andrictemplate<class T1, class T2> 1720b57cec5SDimitry Andric constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andrictemplate<class T1, class T2> 1750b57cec5SDimitry Andric constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andrictemplate<class T1, class T2> 1780b57cec5SDimitry Andric constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 1790b57cec5SDimitry Andric 1800b57cec5SDimitry Andrictemplate<class T1, class T2> 1810b57cec5SDimitry Andric constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andrictemplate<class T1, class T2> 1840b57cec5SDimitry Andric constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andrictemplate<class T1, class T2> 1870b57cec5SDimitry Andric constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andric// C++14 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andrictemplate<class T, T... I> 1920b57cec5SDimitry Andricstruct integer_sequence 1930b57cec5SDimitry Andric{ 1940b57cec5SDimitry Andric typedef T value_type; 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andric static constexpr size_t size() noexcept; 1970b57cec5SDimitry Andric}; 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andrictemplate<size_t... I> 2000b57cec5SDimitry Andric using index_sequence = integer_sequence<size_t, I...>; 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andrictemplate<class T, T N> 2030b57cec5SDimitry Andric using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; 2040b57cec5SDimitry Andrictemplate<size_t N> 2050b57cec5SDimitry Andric using make_index_sequence = make_integer_sequence<size_t, N>; 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andrictemplate<class... T> 2080b57cec5SDimitry Andric using index_sequence_for = make_index_sequence<sizeof...(T)>; 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andrictemplate<class T, class U=T> 211349cc55cSDimitry Andric constexpr T exchange(T& obj, U&& new_value) 212349cc55cSDimitry Andric noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23 2130b57cec5SDimitry Andric 2140b57cec5SDimitry Andric// 20.2.7, in-place construction // C++17 2150b57cec5SDimitry Andricstruct in_place_t { 2160b57cec5SDimitry Andric explicit in_place_t() = default; 2170b57cec5SDimitry Andric}; 2180b57cec5SDimitry Andricinline constexpr in_place_t in_place{}; 2190b57cec5SDimitry Andrictemplate <class T> 2200b57cec5SDimitry Andric struct in_place_type_t { 2210b57cec5SDimitry Andric explicit in_place_type_t() = default; 2220b57cec5SDimitry Andric }; 2230b57cec5SDimitry Andrictemplate <class T> 2240b57cec5SDimitry Andric inline constexpr in_place_type_t<T> in_place_type{}; 2250b57cec5SDimitry Andrictemplate <size_t I> 2260b57cec5SDimitry Andric struct in_place_index_t { 2270b57cec5SDimitry Andric explicit in_place_index_t() = default; 2280b57cec5SDimitry Andric }; 2290b57cec5SDimitry Andrictemplate <size_t I> 2300b57cec5SDimitry Andric inline constexpr in_place_index_t<I> in_place_index{}; 2310b57cec5SDimitry Andric 232fe6060f1SDimitry Andric// [utility.underlying], to_underlying 233fe6060f1SDimitry Andrictemplate <class T> 234fe6060f1SDimitry Andric constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b 235fe6060f1SDimitry Andric 2360b57cec5SDimitry Andric} // std 2370b57cec5SDimitry Andric 2380b57cec5SDimitry Andric*/ 2390b57cec5SDimitry Andric 24081ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 2410b57cec5SDimitry Andric#include <__config> 242fe6060f1SDimitry Andric#include <__utility/as_const.h> 2430eae32dcSDimitry Andric#include <__utility/auto_cast.h> 244fe6060f1SDimitry Andric#include <__utility/cmp.h> 245fe6060f1SDimitry Andric#include <__utility/declval.h> 246*bdd1243dSDimitry Andric#include <__utility/exception_guard.h> 247fe6060f1SDimitry Andric#include <__utility/exchange.h> 248fe6060f1SDimitry Andric#include <__utility/forward.h> 249*bdd1243dSDimitry Andric#include <__utility/forward_like.h> 250fe6060f1SDimitry Andric#include <__utility/in_place.h> 251fe6060f1SDimitry Andric#include <__utility/integer_sequence.h> 252fe6060f1SDimitry Andric#include <__utility/move.h> 253fe6060f1SDimitry Andric#include <__utility/pair.h> 254fe6060f1SDimitry Andric#include <__utility/piecewise_construct.h> 2554824e7fdSDimitry Andric#include <__utility/priority_tag.h> 256fe6060f1SDimitry Andric#include <__utility/rel_ops.h> 257fe6060f1SDimitry Andric#include <__utility/swap.h> 258fe6060f1SDimitry Andric#include <__utility/to_underlying.h> 25981ad6265SDimitry Andric#include <__utility/unreachable.h> 26081ad6265SDimitry Andric#include <version> 26181ad6265SDimitry Andric 26281ad6265SDimitry Andric// standard-mandated includes 263*bdd1243dSDimitry Andric 264*bdd1243dSDimitry Andric// [utility.syn] 265fe6060f1SDimitry Andric#include <compare> 266fe6060f1SDimitry Andric#include <initializer_list> 2670b57cec5SDimitry Andric 268*bdd1243dSDimitry Andric// [tuple.helper] 269*bdd1243dSDimitry Andric#include <__tuple_dir/tuple_element.h> 270*bdd1243dSDimitry Andric#include <__tuple_dir/tuple_size.h> 271*bdd1243dSDimitry Andric 2720eae32dcSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2730eae32dcSDimitry Andric# pragma GCC system_header 2740eae32dcSDimitry Andric#endif 2750eae32dcSDimitry Andric 276*bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 277*bdd1243dSDimitry Andric# include <cstdlib> 278*bdd1243dSDimitry Andric# include <iosfwd> 279*bdd1243dSDimitry Andric# include <type_traits> 280*bdd1243dSDimitry Andric#endif 281*bdd1243dSDimitry Andric 2820b57cec5SDimitry Andric#endif // _LIBCPP_UTILITY 283