xref: /freebsd/contrib/llvm-project/libcxx/include/utility (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===-------------------------- utility -----------------------------------===//
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
450b57cec5SDimitry Andrictemplate <class T> typename remove_reference<T>::type&& move(T&&) noexcept;      // constexpr in C++14
460b57cec5SDimitry Andric
470b57cec5SDimitry Andrictemplate <class T>
480b57cec5SDimitry Andric    typename conditional
490b57cec5SDimitry Andric    <
500b57cec5SDimitry Andric        !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
510b57cec5SDimitry Andric        const T&,
520b57cec5SDimitry Andric        T&&
530b57cec5SDimitry Andric    >::type
540b57cec5SDimitry Andric    move_if_noexcept(T& x) noexcept; // constexpr in C++14
550b57cec5SDimitry Andric
560b57cec5SDimitry Andrictemplate <class T> constexpr add_const_t<T>& as_const(T& t) noexcept;      // C++17
570b57cec5SDimitry Andrictemplate <class T>                      void as_const(const T&&) = delete; // C++17
580b57cec5SDimitry Andric
590b57cec5SDimitry Andrictemplate <class T> typename add_rvalue_reference<T>::type declval() noexcept;
600b57cec5SDimitry Andric
61*fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept;         // C++20
62*fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept;     // C++20
63*fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_less(T t, U u) noexcept;          // C++20
64*fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept;       // C++20
65*fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept;    // C++20
66*fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20
67*fe6060f1SDimitry Andrictemplate<class R, class T> constexpr bool in_range(T t) noexcept;               // C++20
68*fe6060f1SDimitry Andric
690b57cec5SDimitry Andrictemplate <class T1, class T2>
700b57cec5SDimitry Andricstruct pair
710b57cec5SDimitry Andric{
720b57cec5SDimitry Andric    typedef T1 first_type;
730b57cec5SDimitry Andric    typedef T2 second_type;
740b57cec5SDimitry Andric
750b57cec5SDimitry Andric    T1 first;
760b57cec5SDimitry Andric    T2 second;
770b57cec5SDimitry Andric
780b57cec5SDimitry Andric    pair(const pair&) = default;
790b57cec5SDimitry Andric    pair(pair&&) = default;
80e40139ffSDimitry Andric    explicit(see-below) constexpr pair();
81e40139ffSDimitry Andric    explicit(see-below) pair(const T1& x, const T2& y);                          // constexpr in C++14
82e40139ffSDimitry Andric    template <class U, class V> explicit(see-below) pair(U&& x, V&& y);          // constexpr in C++14
83e40139ffSDimitry Andric    template <class U, class V> explicit(see-below) pair(const pair<U, V>& p);   // constexpr in C++14
84e40139ffSDimitry Andric    template <class U, class V> explicit(see-below) pair(pair<U, V>&& p);        // constexpr in C++14
850b57cec5SDimitry Andric    template <class... Args1, class... Args2>
860b57cec5SDimitry Andric        pair(piecewise_construct_t, tuple<Args1...> first_args,
87*fe6060f1SDimitry Andric             tuple<Args2...> second_args);                                       // constexpr in C++20
880b57cec5SDimitry Andric
89*fe6060f1SDimitry Andric    template <class U, class V> pair& operator=(const pair<U, V>& p);            // constexpr in C++20
900b57cec5SDimitry Andric    pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
91*fe6060f1SDimitry Andric                                       is_nothrow_move_assignable<T2>::value);   // constexpr in C++20
92*fe6060f1SDimitry Andric    template <class U, class V> pair& operator=(pair<U, V>&& p);                 // constexpr in C++20
930b57cec5SDimitry Andric
940b57cec5SDimitry Andric    void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
95*fe6060f1SDimitry Andric                                is_nothrow_swappable_v<T2>);                     // constexpr in C++20
960b57cec5SDimitry Andric};
970b57cec5SDimitry Andric
980b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
990b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
1000b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
1010b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
1020b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
1030b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andrictemplate <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);                // constexpr in C++14
1060b57cec5SDimitry Andrictemplate <class T1, class T2>
1070b57cec5SDimitry Andricvoid
108*fe6060f1SDimitry Andricswap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));            // constexpr in C++20
1090b57cec5SDimitry Andric
110e40139ffSDimitry Andricstruct piecewise_construct_t { explicit piecewise_construct_t() = default; };
1110b57cec5SDimitry Andricinline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andrictemplate <class T> struct tuple_size;
1140b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element;
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_size<pair<T1, T2> >;
1170b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
1180b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1210b57cec5SDimitry Andric    typename tuple_element<I, pair<T1, T2> >::type&
1220b57cec5SDimitry Andric    get(pair<T1, T2>&) noexcept; // constexpr in C++14
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1250b57cec5SDimitry Andric    const typename tuple_element<I, pair<T1, T2> >::type&
1260b57cec5SDimitry Andric    get(const pair<T1, T2>&) noexcept; // constexpr in C++14
1270b57cec5SDimitry Andric
1280b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1290b57cec5SDimitry Andric    typename tuple_element<I, pair<T1, T2> >::type&&
1300b57cec5SDimitry Andric    get(pair<T1, T2>&&) noexcept; // constexpr in C++14
1310b57cec5SDimitry Andric
1320b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1330b57cec5SDimitry Andric    const typename tuple_element<I, pair<T1, T2> >::type&&
1340b57cec5SDimitry Andric    get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andrictemplate<class T1, class T2>
1370b57cec5SDimitry Andric    constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
1380b57cec5SDimitry Andric
1390b57cec5SDimitry Andrictemplate<class T1, class T2>
1400b57cec5SDimitry Andric    constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
1410b57cec5SDimitry Andric
1420b57cec5SDimitry Andrictemplate<class T1, class T2>
1430b57cec5SDimitry Andric    constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
1440b57cec5SDimitry Andric
1450b57cec5SDimitry Andrictemplate<class T1, class T2>
1460b57cec5SDimitry Andric    constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andrictemplate<class T1, class T2>
1490b57cec5SDimitry Andric    constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
1500b57cec5SDimitry Andric
1510b57cec5SDimitry Andrictemplate<class T1, class T2>
1520b57cec5SDimitry Andric    constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
1530b57cec5SDimitry Andric
1540b57cec5SDimitry Andrictemplate<class T1, class T2>
1550b57cec5SDimitry Andric    constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
1560b57cec5SDimitry Andric
1570b57cec5SDimitry Andrictemplate<class T1, class T2>
1580b57cec5SDimitry Andric    constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
1590b57cec5SDimitry Andric
1600b57cec5SDimitry Andric// C++14
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andrictemplate<class T, T... I>
1630b57cec5SDimitry Andricstruct integer_sequence
1640b57cec5SDimitry Andric{
1650b57cec5SDimitry Andric    typedef T value_type;
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andric    static constexpr size_t size() noexcept;
1680b57cec5SDimitry Andric};
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andrictemplate<size_t... I>
1710b57cec5SDimitry Andric  using index_sequence = integer_sequence<size_t, I...>;
1720b57cec5SDimitry Andric
1730b57cec5SDimitry Andrictemplate<class T, T N>
1740b57cec5SDimitry Andric  using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
1750b57cec5SDimitry Andrictemplate<size_t N>
1760b57cec5SDimitry Andric  using make_index_sequence = make_integer_sequence<size_t, N>;
1770b57cec5SDimitry Andric
1780b57cec5SDimitry Andrictemplate<class... T>
1790b57cec5SDimitry Andric  using index_sequence_for = make_index_sequence<sizeof...(T)>;
1800b57cec5SDimitry Andric
1810b57cec5SDimitry Andrictemplate<class T, class U=T>
1820b57cec5SDimitry Andric    T exchange(T& obj, U&& new_value);
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andric// 20.2.7, in-place construction // C++17
1850b57cec5SDimitry Andricstruct in_place_t {
1860b57cec5SDimitry Andric  explicit in_place_t() = default;
1870b57cec5SDimitry Andric};
1880b57cec5SDimitry Andricinline constexpr in_place_t in_place{};
1890b57cec5SDimitry Andrictemplate <class T>
1900b57cec5SDimitry Andric  struct in_place_type_t {
1910b57cec5SDimitry Andric    explicit in_place_type_t() = default;
1920b57cec5SDimitry Andric  };
1930b57cec5SDimitry Andrictemplate <class T>
1940b57cec5SDimitry Andric  inline constexpr in_place_type_t<T> in_place_type{};
1950b57cec5SDimitry Andrictemplate <size_t I>
1960b57cec5SDimitry Andric  struct in_place_index_t {
1970b57cec5SDimitry Andric    explicit in_place_index_t() = default;
1980b57cec5SDimitry Andric  };
1990b57cec5SDimitry Andrictemplate <size_t I>
2000b57cec5SDimitry Andric  inline constexpr in_place_index_t<I> in_place_index{};
2010b57cec5SDimitry Andric
202*fe6060f1SDimitry Andric// [utility.underlying], to_underlying
203*fe6060f1SDimitry Andrictemplate <class T>
204*fe6060f1SDimitry Andric    constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b
205*fe6060f1SDimitry Andric
2060b57cec5SDimitry Andric}  // std
2070b57cec5SDimitry Andric
2080b57cec5SDimitry Andric*/
2090b57cec5SDimitry Andric
2100b57cec5SDimitry Andric#include <__config>
2110b57cec5SDimitry Andric#include <__debug>
212*fe6060f1SDimitry Andric#include <__tuple>
213*fe6060f1SDimitry Andric#include <__utility/as_const.h>
214*fe6060f1SDimitry Andric#include <__utility/cmp.h>
215*fe6060f1SDimitry Andric#include <__utility/declval.h>
216*fe6060f1SDimitry Andric#include <__utility/exchange.h>
217*fe6060f1SDimitry Andric#include <__utility/forward.h>
218*fe6060f1SDimitry Andric#include <__utility/in_place.h>
219*fe6060f1SDimitry Andric#include <__utility/integer_sequence.h>
220*fe6060f1SDimitry Andric#include <__utility/move.h>
221*fe6060f1SDimitry Andric#include <__utility/pair.h>
222*fe6060f1SDimitry Andric#include <__utility/piecewise_construct.h>
223*fe6060f1SDimitry Andric#include <__utility/rel_ops.h>
224*fe6060f1SDimitry Andric#include <__utility/swap.h>
225*fe6060f1SDimitry Andric#include <__utility/to_underlying.h>
226*fe6060f1SDimitry Andric#include <compare>
227*fe6060f1SDimitry Andric#include <initializer_list>
228*fe6060f1SDimitry Andric#include <version>
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andric#endif // _LIBCPP_UTILITY
231