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 45bdd1243dSDimitry Andrictemplate <typename T> 46bdd1243dSDimitry Andric[[nodiscard]] constexpr 47bdd1243dSDimitry Andricauto forward_like(auto&& x) noexcept -> see below; // since C++23 48bdd1243dSDimitry 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 8706c3fb27SDimitry 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 90bdd1243dSDimitry Andric template <class U, class V> 9106c3fb27SDimitry Andric constexpr explicit(see-below) pair(const pair<U, V>&&); // since C++23 9206c3fb27SDimitry Andric template <pair-like P> constexpr explicit(see-below) pair(P&&); // since C++23 930b57cec5SDimitry Andric template <class... Args1, class... Args2> 9406c3fb27SDimitry Andric pair(piecewise_construct_t, tuple<Args1...> first_args, // constexpr in C++20 9506c3fb27SDimitry Andric tuple<Args2...> second_args); 960b57cec5SDimitry Andric 97bdd1243dSDimitry Andric constexpr const pair& operator=(const pair& p) const; // since C++23 98fe6060f1SDimitry Andric template <class U, class V> pair& operator=(const pair<U, V>& p); // constexpr in C++20 99bdd1243dSDimitry Andric template <class U, class V> 100bdd1243dSDimitry Andric constexpr const pair& operator=(const pair<U, V>& p) const; // since C++23 1010b57cec5SDimitry Andric pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && 102fe6060f1SDimitry Andric is_nothrow_move_assignable<T2>::value); // constexpr in C++20 103bdd1243dSDimitry Andric constexpr const pair& operator=(pair&& p) const; // since C++23 104fe6060f1SDimitry Andric template <class U, class V> pair& operator=(pair<U, V>&& p); // constexpr in C++20 105bdd1243dSDimitry Andric template <class U, class V> 106bdd1243dSDimitry Andric constexpr const pair& operator=(pair<U, V>&& p) const; // since C++23 10706c3fb27SDimitry Andric template <pair-like P> constexpr pair& operator=(P&&); // since C++23 10806c3fb27SDimitry Andric template <pair-like P> constexpr const pair& operator=(P&&) const; // since C++23 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andric void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> && 111fe6060f1SDimitry Andric is_nothrow_swappable_v<T2>); // constexpr in C++20 112bdd1243dSDimitry Andric constexpr void swap(const pair& p) const noexcept(see below); // since C++23 1130b57cec5SDimitry Andric}; 1140b57cec5SDimitry Andric 11581ad6265SDimitry Andrictemplate<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual> 11681ad6265SDimitry Andricstruct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23 11781ad6265SDimitry Andric 11881ad6265SDimitry Andrictemplate<class T1, class T2, class U1, class U2> 11981ad6265SDimitry Andricstruct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23 12081ad6265SDimitry Andric 121349cc55cSDimitry Andrictemplate<class T1, class T2> pair(T1, T2) -> pair<T1, T2>; 122349cc55cSDimitry Andric 12306c3fb27SDimitry Andrictemplate <class T1, class T2, class U1, class U2> 12406c3fb27SDimitry Andricbool operator==(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14 12506c3fb27SDimitry Andrictemplate <class T1, class T2, class U1, class U2> 12606c3fb27SDimitry Andricbool operator!=(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20 12706c3fb27SDimitry Andrictemplate <class T1, class T2, class U1, class U2> 12806c3fb27SDimitry Andricbool operator< (const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20 12906c3fb27SDimitry Andrictemplate <class T1, class T2, class U1, class U2> 13006c3fb27SDimitry Andricbool operator> (const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20 13106c3fb27SDimitry Andrictemplate <class T1, class T2, class U1, class U2> 13206c3fb27SDimitry Andricbool operator>=(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20 13306c3fb27SDimitry Andrictemplate <class T1, class T2, class U1, class U2> 13406c3fb27SDimitry Andricbool operator<=(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20 13506c3fb27SDimitry Andrictemplate <class T1, class T2, class U1, class U2> 13606c3fb27SDimitry Andric constexpr common_comparison_type_t<synth-three-way-result<T1,U1>, 13706c3fb27SDimitry Andric synth-three-way-result<T2,U2>> 13806c3fb27SDimitry Andric operator<=>(const pair<T1,T2>&, const pair<U1,U2>&); // C++20 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andrictemplate <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 1410b57cec5SDimitry Andrictemplate <class T1, class T2> 1420b57cec5SDimitry Andricvoid 143fe6060f1SDimitry Andricswap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 1440b57cec5SDimitry Andric 14506c3fb27SDimitry Andrictemplate<class T1, class T2> // since C++23 14606c3fb27SDimitry Andricconstexpr void swap(const pair<T1, T2>& x, const pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); 147bdd1243dSDimitry Andric 148e40139ffSDimitry Andricstruct piecewise_construct_t { explicit piecewise_construct_t() = default; }; 1490b57cec5SDimitry Andricinline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 1500b57cec5SDimitry Andric 1510b57cec5SDimitry Andrictemplate <class T> struct tuple_size; 1520b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; 1530b57cec5SDimitry Andric 1540b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_size<pair<T1, T2> >; 1550b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; 1560b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1590b57cec5SDimitry Andric typename tuple_element<I, pair<T1, T2> >::type& 1600b57cec5SDimitry Andric get(pair<T1, T2>&) noexcept; // constexpr in C++14 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1630b57cec5SDimitry Andric const typename tuple_element<I, pair<T1, T2> >::type& 1640b57cec5SDimitry Andric get(const pair<T1, T2>&) noexcept; // constexpr in C++14 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1670b57cec5SDimitry Andric typename tuple_element<I, pair<T1, T2> >::type&& 1680b57cec5SDimitry Andric get(pair<T1, T2>&&) noexcept; // constexpr in C++14 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1710b57cec5SDimitry Andric const typename tuple_element<I, pair<T1, T2> >::type&& 1720b57cec5SDimitry Andric get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andrictemplate<class T1, class T2> 1750b57cec5SDimitry Andric constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andrictemplate<class T1, class T2> 1780b57cec5SDimitry Andric constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 1790b57cec5SDimitry Andric 1800b57cec5SDimitry Andrictemplate<class T1, class T2> 1810b57cec5SDimitry Andric constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andrictemplate<class T1, class T2> 1840b57cec5SDimitry Andric constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andrictemplate<class T1, class T2> 1870b57cec5SDimitry Andric constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andrictemplate<class T1, class T2> 1900b57cec5SDimitry Andric constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andrictemplate<class T1, class T2> 1930b57cec5SDimitry Andric constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andrictemplate<class T1, class T2> 1960b57cec5SDimitry Andric constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andric// C++14 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andrictemplate<class T, T... I> 2010b57cec5SDimitry Andricstruct integer_sequence 2020b57cec5SDimitry Andric{ 2030b57cec5SDimitry Andric typedef T value_type; 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andric static constexpr size_t size() noexcept; 2060b57cec5SDimitry Andric}; 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andrictemplate<size_t... I> 2090b57cec5SDimitry Andric using index_sequence = integer_sequence<size_t, I...>; 2100b57cec5SDimitry Andric 2110b57cec5SDimitry Andrictemplate<class T, T N> 2120b57cec5SDimitry Andric using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; 2130b57cec5SDimitry Andrictemplate<size_t N> 2140b57cec5SDimitry Andric using make_index_sequence = make_integer_sequence<size_t, N>; 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andrictemplate<class... T> 2170b57cec5SDimitry Andric using index_sequence_for = make_index_sequence<sizeof...(T)>; 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andrictemplate<class T, class U=T> 22006c3fb27SDimitry Andric constexpr T exchange(T& obj, U&& new_value) // constexpr in C++17, noexcept in C++23 22106c3fb27SDimitry Andric noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric// 20.2.7, in-place construction // C++17 2240b57cec5SDimitry Andricstruct in_place_t { 2250b57cec5SDimitry Andric explicit in_place_t() = default; 2260b57cec5SDimitry Andric}; 2270b57cec5SDimitry Andricinline constexpr in_place_t in_place{}; 2280b57cec5SDimitry Andrictemplate <class T> 2290b57cec5SDimitry Andric struct in_place_type_t { 2300b57cec5SDimitry Andric explicit in_place_type_t() = default; 2310b57cec5SDimitry Andric }; 2320b57cec5SDimitry Andrictemplate <class T> 2330b57cec5SDimitry Andric inline constexpr in_place_type_t<T> in_place_type{}; 2340b57cec5SDimitry Andrictemplate <size_t I> 2350b57cec5SDimitry Andric struct in_place_index_t { 2360b57cec5SDimitry Andric explicit in_place_index_t() = default; 2370b57cec5SDimitry Andric }; 2380b57cec5SDimitry Andrictemplate <size_t I> 2390b57cec5SDimitry Andric inline constexpr in_place_index_t<I> in_place_index{}; 2400b57cec5SDimitry Andric 241fe6060f1SDimitry Andric// [utility.underlying], to_underlying 242fe6060f1SDimitry Andrictemplate <class T> 24306c3fb27SDimitry Andric constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++23 244fe6060f1SDimitry Andric 2450b57cec5SDimitry Andric} // std 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andric*/ 2480b57cec5SDimitry Andric 2490b57cec5SDimitry Andric#include <__config> 250*0fca6ea1SDimitry Andric 251fe6060f1SDimitry Andric#include <__utility/declval.h> 252fe6060f1SDimitry Andric#include <__utility/forward.h> 253fe6060f1SDimitry Andric#include <__utility/move.h> 254fe6060f1SDimitry Andric#include <__utility/pair.h> 255fe6060f1SDimitry Andric#include <__utility/piecewise_construct.h> 256fe6060f1SDimitry Andric#include <__utility/rel_ops.h> 257fe6060f1SDimitry Andric#include <__utility/swap.h> 258*0fca6ea1SDimitry Andric 259*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 14 260*0fca6ea1SDimitry Andric# include <__utility/exchange.h> 261*0fca6ea1SDimitry Andric# include <__utility/integer_sequence.h> 262*0fca6ea1SDimitry Andric#endif 263*0fca6ea1SDimitry Andric 264*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 17 265*0fca6ea1SDimitry Andric# include <__utility/as_const.h> 266*0fca6ea1SDimitry Andric# include <__utility/in_place.h> 267*0fca6ea1SDimitry Andric#endif 268*0fca6ea1SDimitry Andric 269*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20 270*0fca6ea1SDimitry Andric# include <__utility/cmp.h> 271*0fca6ea1SDimitry Andric#endif 272*0fca6ea1SDimitry Andric 273*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 23 274*0fca6ea1SDimitry Andric# include <__utility/forward_like.h> 275fe6060f1SDimitry Andric# include <__utility/to_underlying.h> 27681ad6265SDimitry Andric# include <__utility/unreachable.h> 277*0fca6ea1SDimitry Andric#endif 278*0fca6ea1SDimitry Andric 27981ad6265SDimitry Andric#include <version> 28081ad6265SDimitry Andric 28181ad6265SDimitry Andric// standard-mandated includes 282bdd1243dSDimitry Andric 283bdd1243dSDimitry Andric// [utility.syn] 284fe6060f1SDimitry Andric#include <compare> 285fe6060f1SDimitry Andric#include <initializer_list> 2860b57cec5SDimitry Andric 287*0fca6ea1SDimitry Andric// [tuple.creation] 288*0fca6ea1SDimitry Andric 289*0fca6ea1SDimitry Andric#include <__tuple/ignore.h> 290*0fca6ea1SDimitry Andric 291bdd1243dSDimitry Andric// [tuple.helper] 29206c3fb27SDimitry Andric#include <__tuple/tuple_element.h> 29306c3fb27SDimitry Andric#include <__tuple/tuple_size.h> 294bdd1243dSDimitry Andric 2950eae32dcSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2960eae32dcSDimitry Andric# pragma GCC system_header 2970eae32dcSDimitry Andric#endif 2980eae32dcSDimitry Andric 299bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 300*0fca6ea1SDimitry Andric# include <limits> 301*0fca6ea1SDimitry Andric#endif 302*0fca6ea1SDimitry Andric 303*0fca6ea1SDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 304bdd1243dSDimitry Andric# include <cstdlib> 305bdd1243dSDimitry Andric# include <iosfwd> 306bdd1243dSDimitry Andric# include <type_traits> 307bdd1243dSDimitry Andric#endif 308bdd1243dSDimitry Andric 3090b57cec5SDimitry Andric#endif // _LIBCPP_UTILITY 310