xref: /freebsd/contrib/llvm-project/libcxx/include/utility (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
10b57cec5SDimitry Andric// -*- C++ -*-
2*349cc55cSDimitry 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
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
61fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept;         // C++20
62fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept;     // C++20
63fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_less(T t, U u) noexcept;          // C++20
64fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept;       // C++20
65fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept;    // C++20
66fe6060f1SDimitry Andrictemplate<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20
67fe6060f1SDimitry Andrictemplate<class R, class T> constexpr bool in_range(T t) noexcept;               // C++20
68fe6060f1SDimitry 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
82*349cc55cSDimitry Andric    template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&);    // 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,
87fe6060f1SDimitry Andric             tuple<Args2...> second_args);                                       // constexpr in C++20
880b57cec5SDimitry Andric
89fe6060f1SDimitry 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 &&
91fe6060f1SDimitry Andric                                       is_nothrow_move_assignable<T2>::value);   // constexpr in C++20
92fe6060f1SDimitry 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> &&
95fe6060f1SDimitry Andric                                is_nothrow_swappable_v<T2>);                     // constexpr in C++20
960b57cec5SDimitry Andric};
970b57cec5SDimitry Andric
98*349cc55cSDimitry Andrictemplate<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
99*349cc55cSDimitry Andric
1000b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
101*349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
102*349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
103*349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
104*349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
105*349cc55cSDimitry Andrictemplate <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
106*349cc55cSDimitry Andrictemplate <class T1, class T2>
107*349cc55cSDimitry Andric  constexpr common_comparison_type_t<synth-three-way-result<T1>,
108*349cc55cSDimitry Andric                                     synth-three-way-result<T2>>
109*349cc55cSDimitry Andric    operator<=>(const pair<T1,T2>&, const pair<T1,T2>&);                               // C++20
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andrictemplate <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);                // constexpr in C++14
1120b57cec5SDimitry Andrictemplate <class T1, class T2>
1130b57cec5SDimitry Andricvoid
114fe6060f1SDimitry Andricswap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));            // constexpr in C++20
1150b57cec5SDimitry Andric
116e40139ffSDimitry Andricstruct piecewise_construct_t { explicit piecewise_construct_t() = default; };
1170b57cec5SDimitry Andricinline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andrictemplate <class T> struct tuple_size;
1200b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element;
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_size<pair<T1, T2> >;
1230b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
1240b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
1250b57cec5SDimitry Andric
1260b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1270b57cec5SDimitry Andric    typename tuple_element<I, pair<T1, T2> >::type&
1280b57cec5SDimitry Andric    get(pair<T1, T2>&) noexcept; // constexpr in C++14
1290b57cec5SDimitry Andric
1300b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1310b57cec5SDimitry Andric    const typename tuple_element<I, pair<T1, T2> >::type&
1320b57cec5SDimitry Andric    get(const pair<T1, T2>&) noexcept; // constexpr in C++14
1330b57cec5SDimitry Andric
1340b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1350b57cec5SDimitry Andric    typename tuple_element<I, pair<T1, T2> >::type&&
1360b57cec5SDimitry Andric    get(pair<T1, T2>&&) noexcept; // constexpr in C++14
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2>
1390b57cec5SDimitry Andric    const typename tuple_element<I, pair<T1, T2> >::type&&
1400b57cec5SDimitry Andric    get(const pair<T1, T2>&&) noexcept; // constexpr in 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<T1, T2>&&) noexcept; // C++14
1500b57cec5SDimitry Andric
1510b57cec5SDimitry Andrictemplate<class T1, class T2>
1520b57cec5SDimitry Andric    constexpr const T1&& get(const pair<T1, T2>&&) 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 Andrictemplate<class T1, class T2>
1610b57cec5SDimitry Andric    constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
1620b57cec5SDimitry Andric
1630b57cec5SDimitry Andrictemplate<class T1, class T2>
1640b57cec5SDimitry Andric    constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
1650b57cec5SDimitry Andric
1660b57cec5SDimitry Andric// C++14
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andrictemplate<class T, T... I>
1690b57cec5SDimitry Andricstruct integer_sequence
1700b57cec5SDimitry Andric{
1710b57cec5SDimitry Andric    typedef T value_type;
1720b57cec5SDimitry Andric
1730b57cec5SDimitry Andric    static constexpr size_t size() noexcept;
1740b57cec5SDimitry Andric};
1750b57cec5SDimitry Andric
1760b57cec5SDimitry Andrictemplate<size_t... I>
1770b57cec5SDimitry Andric  using index_sequence = integer_sequence<size_t, I...>;
1780b57cec5SDimitry Andric
1790b57cec5SDimitry Andrictemplate<class T, T N>
1800b57cec5SDimitry Andric  using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
1810b57cec5SDimitry Andrictemplate<size_t N>
1820b57cec5SDimitry Andric  using make_index_sequence = make_integer_sequence<size_t, N>;
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andrictemplate<class... T>
1850b57cec5SDimitry Andric  using index_sequence_for = make_index_sequence<sizeof...(T)>;
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andrictemplate<class T, class U=T>
188*349cc55cSDimitry Andric    constexpr T exchange(T& obj, U&& new_value)
189*349cc55cSDimitry Andric      noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23
1900b57cec5SDimitry Andric
1910b57cec5SDimitry Andric// 20.2.7, in-place construction // C++17
1920b57cec5SDimitry Andricstruct in_place_t {
1930b57cec5SDimitry Andric  explicit in_place_t() = default;
1940b57cec5SDimitry Andric};
1950b57cec5SDimitry Andricinline constexpr in_place_t in_place{};
1960b57cec5SDimitry Andrictemplate <class T>
1970b57cec5SDimitry Andric  struct in_place_type_t {
1980b57cec5SDimitry Andric    explicit in_place_type_t() = default;
1990b57cec5SDimitry Andric  };
2000b57cec5SDimitry Andrictemplate <class T>
2010b57cec5SDimitry Andric  inline constexpr in_place_type_t<T> in_place_type{};
2020b57cec5SDimitry Andrictemplate <size_t I>
2030b57cec5SDimitry Andric  struct in_place_index_t {
2040b57cec5SDimitry Andric    explicit in_place_index_t() = default;
2050b57cec5SDimitry Andric  };
2060b57cec5SDimitry Andrictemplate <size_t I>
2070b57cec5SDimitry Andric  inline constexpr in_place_index_t<I> in_place_index{};
2080b57cec5SDimitry Andric
209fe6060f1SDimitry Andric// [utility.underlying], to_underlying
210fe6060f1SDimitry Andrictemplate <class T>
211fe6060f1SDimitry Andric    constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b
212fe6060f1SDimitry Andric
2130b57cec5SDimitry Andric}  // std
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric*/
2160b57cec5SDimitry Andric
2170b57cec5SDimitry Andric#include <__config>
2180b57cec5SDimitry Andric#include <__debug>
219fe6060f1SDimitry Andric#include <__tuple>
220fe6060f1SDimitry Andric#include <__utility/as_const.h>
221fe6060f1SDimitry Andric#include <__utility/cmp.h>
222fe6060f1SDimitry Andric#include <__utility/declval.h>
223fe6060f1SDimitry Andric#include <__utility/exchange.h>
224fe6060f1SDimitry Andric#include <__utility/forward.h>
225fe6060f1SDimitry Andric#include <__utility/in_place.h>
226fe6060f1SDimitry Andric#include <__utility/integer_sequence.h>
227fe6060f1SDimitry Andric#include <__utility/move.h>
228fe6060f1SDimitry Andric#include <__utility/pair.h>
229fe6060f1SDimitry Andric#include <__utility/piecewise_construct.h>
230fe6060f1SDimitry Andric#include <__utility/rel_ops.h>
231fe6060f1SDimitry Andric#include <__utility/swap.h>
232fe6060f1SDimitry Andric#include <__utility/to_underlying.h>
233fe6060f1SDimitry Andric#include <compare>
234fe6060f1SDimitry Andric#include <initializer_list>
235fe6060f1SDimitry Andric#include <version>
2360b57cec5SDimitry Andric
2370b57cec5SDimitry Andric#endif // _LIBCPP_UTILITY
238