xref: /freebsd/contrib/llvm-project/libcxx/include/utility (revision d4eeb02986980bf33dd56c41ceb9fc5f180c0d47)
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
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 = T1, class V = T2> explicit(see-below) pair(U&&, V&&);    // 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> pair(T1, T2) -> pair<T1, T2>;
99
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, removed in C++20
102template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
103template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
104template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
105template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
106template <class T1, class T2>
107  constexpr common_comparison_type_t<synth-three-way-result<T1>,
108                                     synth-three-way-result<T2>>
109    operator<=>(const pair<T1,T2>&, const pair<T1,T2>&);                               // C++20
110
111template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);                // constexpr in C++14
112template <class T1, class T2>
113void
114swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));            // constexpr in C++20
115
116struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
117inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
118
119template <class T> struct tuple_size;
120template <size_t I, class T> struct tuple_element;
121
122template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
123template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
124template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
125
126template<size_t I, class T1, class T2>
127    typename tuple_element<I, pair<T1, T2> >::type&
128    get(pair<T1, T2>&) noexcept; // constexpr in C++14
129
130template<size_t I, class T1, class T2>
131    const typename tuple_element<I, pair<T1, T2> >::type&
132    get(const pair<T1, T2>&) noexcept; // constexpr in C++14
133
134template<size_t I, class T1, class T2>
135    typename tuple_element<I, pair<T1, T2> >::type&&
136    get(pair<T1, T2>&&) noexcept; // constexpr in C++14
137
138template<size_t I, class T1, class T2>
139    const typename tuple_element<I, pair<T1, T2> >::type&&
140    get(const pair<T1, T2>&&) noexcept; // constexpr in 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<T1, T2>&&) noexcept; // C++14
150
151template<class T1, class T2>
152    constexpr const T1&& get(const pair<T1, T2>&&) 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
160template<class T1, class T2>
161    constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
162
163template<class T1, class T2>
164    constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
165
166// C++14
167
168template<class T, T... I>
169struct integer_sequence
170{
171    typedef T value_type;
172
173    static constexpr size_t size() noexcept;
174};
175
176template<size_t... I>
177  using index_sequence = integer_sequence<size_t, I...>;
178
179template<class T, T N>
180  using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
181template<size_t N>
182  using make_index_sequence = make_integer_sequence<size_t, N>;
183
184template<class... T>
185  using index_sequence_for = make_index_sequence<sizeof...(T)>;
186
187template<class T, class U=T>
188    constexpr T exchange(T& obj, U&& new_value)
189      noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23
190
191// 20.2.7, in-place construction // C++17
192struct in_place_t {
193  explicit in_place_t() = default;
194};
195inline constexpr in_place_t in_place{};
196template <class T>
197  struct in_place_type_t {
198    explicit in_place_type_t() = default;
199  };
200template <class T>
201  inline constexpr in_place_type_t<T> in_place_type{};
202template <size_t I>
203  struct in_place_index_t {
204    explicit in_place_index_t() = default;
205  };
206template <size_t I>
207  inline constexpr in_place_index_t<I> in_place_index{};
208
209// [utility.underlying], to_underlying
210template <class T>
211    constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b
212
213}  // std
214
215*/
216
217#include <__config>
218#include <__debug>
219#include <__tuple>
220#include <__utility/as_const.h>
221#include <__utility/auto_cast.h>
222#include <__utility/cmp.h>
223#include <__utility/declval.h>
224#include <__utility/exchange.h>
225#include <__utility/forward.h>
226#include <__utility/in_place.h>
227#include <__utility/integer_sequence.h>
228#include <__utility/move.h>
229#include <__utility/pair.h>
230#include <__utility/piecewise_construct.h>
231#include <__utility/priority_tag.h>
232#include <__utility/rel_ops.h>
233#include <__utility/swap.h>
234#include <__utility/to_underlying.h>
235#include <__utility/transaction.h>
236#include <compare>
237#include <initializer_list>
238#include <version>
239
240#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241#pragma GCC system_header
242#endif
243
244#endif // _LIBCPP_UTILITY
245