2010-05-11 19:42:16 +00:00
|
|
|
// -*- C++ -*-
|
2021-11-17 16:25:01 -05:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_UTILITY
|
|
|
|
#define _LIBCPP_UTILITY
|
|
|
|
|
|
|
|
/*
|
|
|
|
utility synopsis
|
|
|
|
|
2018-07-05 16:16:03 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void
|
|
|
|
swap(T& a, T& b);
|
|
|
|
|
|
|
|
namespace rel_ops
|
|
|
|
{
|
|
|
|
template<class T> bool operator!=(const T&, const T&);
|
|
|
|
template<class T> bool operator> (const T&, const T&);
|
|
|
|
template<class T> bool operator<=(const T&, const T&);
|
|
|
|
template<class T> bool operator>=(const T&, const T&);
|
|
|
|
}
|
|
|
|
|
2011-05-27 15:04:19 +00:00
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
|
|
|
|
is_nothrow_move_assignable<T>::value);
|
|
|
|
|
|
|
|
template <class T, size_t N>
|
|
|
|
void
|
|
|
|
swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2013-07-15 20:46:11 +00:00
|
|
|
template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14
|
|
|
|
template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14
|
2011-05-27 15:04:19 +00:00
|
|
|
|
2022-08-21 22:21:08 +07:00
|
|
|
template <typename T>
|
|
|
|
[[nodiscard]] constexpr
|
|
|
|
auto forward_like(auto&& x) noexcept -> see below; // since C++23
|
|
|
|
|
2013-07-15 20:46:11 +00:00
|
|
|
template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
typename conditional
|
|
|
|
<
|
2010-11-19 22:17:28 +00:00
|
|
|
!is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
|
2010-05-11 19:42:16 +00:00
|
|
|
const T&,
|
|
|
|
T&&
|
|
|
|
>::type
|
2013-07-15 20:46:11 +00:00
|
|
|
move_if_noexcept(T& x) noexcept; // constexpr in C++14
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2018-02-11 21:51:49 +00:00
|
|
|
template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17
|
2015-11-17 00:08:08 +00:00
|
|
|
template <class T> void as_const(const T&&) = delete; // C++17
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
|
|
|
|
|
2021-04-20 04:48:34 +05:30
|
|
|
template<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept; // C++20
|
|
|
|
template<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20
|
|
|
|
template<class T, class U> constexpr bool cmp_less(T t, U u) noexcept; // C++20
|
|
|
|
template<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept; // C++20
|
|
|
|
template<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20
|
|
|
|
template<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20
|
|
|
|
template<class R, class T> constexpr bool in_range(T t) noexcept; // C++20
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class T1, class T2>
|
|
|
|
struct pair
|
|
|
|
{
|
|
|
|
typedef T1 first_type;
|
|
|
|
typedef T2 second_type;
|
|
|
|
|
|
|
|
T1 first;
|
|
|
|
T2 second;
|
|
|
|
|
|
|
|
pair(const pair&) = default;
|
2011-05-27 15:04:19 +00:00
|
|
|
pair(pair&&) = default;
|
2019-09-26 14:51:10 +00:00
|
|
|
explicit(see-below) constexpr pair();
|
2019-07-22 20:45:23 +00:00
|
|
|
explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14
|
2021-08-31 18:13:33 -04:00
|
|
|
template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&); // constexpr in C++14
|
2023-02-07 15:21:08 -08:00
|
|
|
template <class U, class V> constexpr explicit(see-below) pair(pair<U, V>&); // since C++23
|
2019-07-22 20:45:23 +00:00
|
|
|
template <class U, class V> explicit(see-below) pair(const pair<U, V>& p); // constexpr in C++14
|
|
|
|
template <class U, class V> explicit(see-below) pair(pair<U, V>&& p); // constexpr in C++14
|
2022-08-09 14:56:30 +01:00
|
|
|
template <class U, class V>
|
2023-02-07 15:21:08 -08:00
|
|
|
constexpr explicit(see-below) pair(const pair<U, V>&&); // since C++23
|
|
|
|
template <pair-like P> constexpr explicit(see-below) pair(P&&); // since C++23
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class... Args1, class... Args2>
|
2023-02-07 15:21:08 -08:00
|
|
|
pair(piecewise_construct_t, tuple<Args1...> first_args, // constexpr in C++20
|
|
|
|
tuple<Args2...> second_args);
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2022-08-09 14:56:30 +01:00
|
|
|
constexpr const pair& operator=(const pair& p) const; // since C++23
|
2021-02-09 19:12:16 -05:00
|
|
|
template <class U, class V> pair& operator=(const pair<U, V>& p); // constexpr in C++20
|
2022-08-09 14:56:30 +01:00
|
|
|
template <class U, class V>
|
|
|
|
constexpr const pair& operator=(const pair<U, V>& p) const; // since C++23
|
2011-05-27 15:04:19 +00:00
|
|
|
pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
|
2021-02-09 19:12:16 -05:00
|
|
|
is_nothrow_move_assignable<T2>::value); // constexpr in C++20
|
2022-08-09 14:56:30 +01:00
|
|
|
constexpr const pair& operator=(pair&& p) const; // since C++23
|
2021-02-09 19:12:16 -05:00
|
|
|
template <class U, class V> pair& operator=(pair<U, V>&& p); // constexpr in C++20
|
2022-08-09 14:56:30 +01:00
|
|
|
template <class U, class V>
|
|
|
|
constexpr const pair& operator=(pair<U, V>&& p) const; // since C++23
|
2023-02-07 15:21:08 -08:00
|
|
|
template <pair-like P> constexpr pair& operator=(P&&); // since C++23
|
|
|
|
template <pair-like P> constexpr const pair& operator=(P&&) const; // since C++23
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2016-04-21 23:38:59 +00:00
|
|
|
void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
|
2021-02-09 19:12:16 -05:00
|
|
|
is_nothrow_swappable_v<T2>); // constexpr in C++20
|
2022-08-09 14:56:30 +01:00
|
|
|
constexpr void swap(const pair& p) const noexcept(see below); // since C++23
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2022-02-01 21:36:50 +01:00
|
|
|
template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual>
|
|
|
|
struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23
|
|
|
|
|
|
|
|
template<class T1, class T2, class U1, class U2>
|
|
|
|
struct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23
|
|
|
|
|
2021-10-28 00:36:19 -07:00
|
|
|
template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
|
|
|
|
|
2023-03-10 09:01:52 +07:00
|
|
|
template <class T1, class T2, class U1, class U2>
|
|
|
|
bool operator==(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14
|
|
|
|
template <class T1, class T2, class U1, class U2>
|
|
|
|
bool operator!=(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20
|
|
|
|
template <class T1, class T2, class U1, class U2>
|
|
|
|
bool operator< (const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20
|
|
|
|
template <class T1, class T2, class U1, class U2>
|
|
|
|
bool operator> (const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20
|
|
|
|
template <class T1, class T2, class U1, class U2>
|
|
|
|
bool operator>=(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20
|
|
|
|
template <class T1, class T2, class U1, class U2>
|
|
|
|
bool operator<=(const pair<T1,T2>&, const pair<U1,U2>&); // constexpr in C++14, removed in C++20
|
|
|
|
template <class T1, class T2, class U1, class U2>
|
|
|
|
constexpr common_comparison_type_t<synth-three-way-result<T1,U1>,
|
|
|
|
synth-three-way-result<T2,U2>>
|
|
|
|
operator<=>(const pair<T1,T2>&, const pair<U1,U2>&); // C++20
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2021-02-09 19:12:16 -05:00
|
|
|
template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
|
2011-05-27 15:04:19 +00:00
|
|
|
template <class T1, class T2>
|
|
|
|
void
|
2021-02-09 19:12:16 -05:00
|
|
|
swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2023-02-24 21:35:41 +01:00
|
|
|
template<class T1, class T2> // since C++23
|
|
|
|
constexpr void swap(const pair<T1, T2>& x, const pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
|
2022-08-09 14:56:30 +01:00
|
|
|
|
2019-09-26 14:51:10 +00:00
|
|
|
struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
|
2018-01-02 17:17:01 +00:00
|
|
|
inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2019-01-11 21:57:12 +00:00
|
|
|
template <class T> struct tuple_size;
|
2019-04-01 16:39:34 +00:00
|
|
|
template <size_t I, class T> struct tuple_element;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2014-03-03 06:18:11 +00:00
|
|
|
template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
|
|
|
|
template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
|
|
|
|
template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template<size_t I, class T1, class T2>
|
2014-03-03 06:18:11 +00:00
|
|
|
typename tuple_element<I, pair<T1, T2> >::type&
|
|
|
|
get(pair<T1, T2>&) noexcept; // constexpr in C++14
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template<size_t I, class T1, class T2>
|
2015-11-19 19:45:29 +00:00
|
|
|
const typename tuple_element<I, pair<T1, T2> >::type&
|
2014-03-03 06:18:11 +00:00
|
|
|
get(const pair<T1, T2>&) noexcept; // constexpr in C++14
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-11-17 19:52:17 +00:00
|
|
|
template<size_t I, class T1, class T2>
|
2014-03-03 06:18:11 +00:00
|
|
|
typename tuple_element<I, pair<T1, T2> >::type&&
|
|
|
|
get(pair<T1, T2>&&) noexcept; // constexpr in C++14
|
2010-11-17 19:52:17 +00:00
|
|
|
|
2015-12-18 00:36:55 +00:00
|
|
|
template<size_t I, class T1, class T2>
|
|
|
|
const typename tuple_element<I, pair<T1, T2> >::type&&
|
|
|
|
get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
|
|
|
|
|
2013-07-13 02:54:05 +00:00
|
|
|
template<class T1, class T2>
|
2014-03-03 06:18:11 +00:00
|
|
|
constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
|
2013-07-13 02:54:05 +00:00
|
|
|
|
2015-12-18 00:36:55 +00:00
|
|
|
template<class T1, class T2>
|
2015-11-19 19:45:29 +00:00
|
|
|
constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
|
2013-07-13 02:54:05 +00:00
|
|
|
|
2015-12-18 00:36:55 +00:00
|
|
|
template<class T1, class T2>
|
2014-03-03 06:18:11 +00:00
|
|
|
constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
|
2013-07-13 02:54:05 +00:00
|
|
|
|
2015-12-18 00:36:55 +00:00
|
|
|
template<class T1, class T2>
|
|
|
|
constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
|
|
|
|
|
|
|
|
template<class T1, class T2>
|
|
|
|
constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
|
|
|
|
|
|
|
|
template<class T1, class T2>
|
|
|
|
constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
|
|
|
|
|
|
|
|
template<class T1, class T2>
|
|
|
|
constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
|
|
|
|
|
|
|
|
template<class T1, class T2>
|
|
|
|
constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
|
|
|
|
|
2013-07-01 16:26:55 +00:00
|
|
|
// C++14
|
|
|
|
|
|
|
|
template<class T, T... I>
|
|
|
|
struct integer_sequence
|
|
|
|
{
|
|
|
|
typedef T value_type;
|
|
|
|
|
|
|
|
static constexpr size_t size() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<size_t... I>
|
|
|
|
using index_sequence = integer_sequence<size_t, I...>;
|
|
|
|
|
|
|
|
template<class T, T N>
|
|
|
|
using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
|
|
|
|
template<size_t N>
|
|
|
|
using make_index_sequence = make_integer_sequence<size_t, N>;
|
|
|
|
|
|
|
|
template<class... T>
|
|
|
|
using index_sequence_for = make_index_sequence<sizeof...(T)>;
|
|
|
|
|
2016-06-19 19:29:52 +00:00
|
|
|
template<class T, class U=T>
|
2023-02-24 21:35:41 +01:00
|
|
|
constexpr T exchange(T& obj, U&& new_value) // constexpr in C++17, noexcept in C++23
|
|
|
|
noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value);
|
2016-07-23 22:19:19 +00:00
|
|
|
|
|
|
|
// 20.2.7, in-place construction // C++17
|
2016-11-17 19:24:04 +00:00
|
|
|
struct in_place_t {
|
|
|
|
explicit in_place_t() = default;
|
|
|
|
};
|
|
|
|
inline constexpr in_place_t in_place{};
|
2016-07-23 22:19:19 +00:00
|
|
|
template <class T>
|
2016-11-17 19:24:04 +00:00
|
|
|
struct in_place_type_t {
|
|
|
|
explicit in_place_type_t() = default;
|
|
|
|
};
|
2016-07-23 22:19:19 +00:00
|
|
|
template <class T>
|
2016-11-17 19:24:04 +00:00
|
|
|
inline constexpr in_place_type_t<T> in_place_type{};
|
2016-07-23 22:19:19 +00:00
|
|
|
template <size_t I>
|
2016-11-17 19:24:04 +00:00
|
|
|
struct in_place_index_t {
|
|
|
|
explicit in_place_index_t() = default;
|
|
|
|
};
|
|
|
|
template <size_t I>
|
|
|
|
inline constexpr in_place_index_t<I> in_place_index{};
|
2016-07-23 22:19:19 +00:00
|
|
|
|
2021-03-05 09:19:39 +01:00
|
|
|
// [utility.underlying], to_underlying
|
|
|
|
template <class T>
|
2023-05-17 17:54:53 +02:00
|
|
|
constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++23
|
2021-03-05 09:19:39 +01:00
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-03-25 12:55:36 -04:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2010-05-11 19:42:16 +00:00
|
|
|
#include <__config>
|
2021-06-09 23:10:17 +00:00
|
|
|
#include <__utility/as_const.h>
|
2021-12-13 19:21:38 -05:00
|
|
|
#include <__utility/auto_cast.h>
|
2021-06-09 23:10:17 +00:00
|
|
|
#include <__utility/cmp.h>
|
2021-06-05 02:47:47 +00:00
|
|
|
#include <__utility/declval.h>
|
[libc++] Improve binary size when using __transaction
__exception_guard is a no-op in -fno-exceptions mode to produce better code-gen. This means that we don't provide the strong exception guarantees. However, Clang doesn't generate cleanup code with exceptions disabled, so even if we wanted to provide the strong exception guarantees we couldn't. This is also only relevant for constructs with a stack of -fexceptions > -fno-exceptions > -fexceptions code, since the exception can't be caught where exceptions are disabled. While -fexceptions > -fno-exceptions is quite common (e.g. libc++.dylib > -fno-exceptions), having another layer with exceptions enabled seems a lot less common, especially one that tries to catch an exception through -fno-exceptions code.
Fixes https://github.com/llvm/llvm-project/issues/56783
Reviewed By: ldionne, Mordante, huixie90, #libc
Spies: EricWF, alexfh, hans, joanahalili, libcxx-commits
Differential Revision: https://reviews.llvm.org/D133661
2022-12-08 09:40:54 +01:00
|
|
|
#include <__utility/exception_guard.h>
|
2021-06-09 23:10:17 +00:00
|
|
|
#include <__utility/exchange.h>
|
2021-06-05 02:47:47 +00:00
|
|
|
#include <__utility/forward.h>
|
2022-08-21 22:21:08 +07:00
|
|
|
#include <__utility/forward_like.h>
|
2021-06-09 23:10:17 +00:00
|
|
|
#include <__utility/in_place.h>
|
|
|
|
#include <__utility/integer_sequence.h>
|
2021-06-05 02:47:47 +00:00
|
|
|
#include <__utility/move.h>
|
2021-06-09 23:10:17 +00:00
|
|
|
#include <__utility/pair.h>
|
|
|
|
#include <__utility/piecewise_construct.h>
|
2021-07-28 22:04:18 -04:00
|
|
|
#include <__utility/priority_tag.h>
|
2021-06-09 23:10:17 +00:00
|
|
|
#include <__utility/rel_ops.h>
|
2021-06-05 02:47:47 +00:00
|
|
|
#include <__utility/swap.h>
|
2021-04-24 17:28:35 +02:00
|
|
|
#include <__utility/to_underlying.h>
|
2022-02-14 18:26:02 +01:00
|
|
|
#include <__utility/unreachable.h>
|
2018-09-12 19:41:40 +00:00
|
|
|
#include <version>
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2022-06-16 22:43:46 +02:00
|
|
|
// standard-mandated includes
|
2022-09-05 14:38:24 +02:00
|
|
|
|
|
|
|
// [utility.syn]
|
2022-06-16 22:43:46 +02:00
|
|
|
#include <compare>
|
|
|
|
#include <initializer_list>
|
|
|
|
|
2022-09-05 14:38:24 +02:00
|
|
|
// [tuple.helper]
|
2023-04-04 13:05:59 +02:00
|
|
|
#include <__tuple/tuple_element.h>
|
|
|
|
#include <__tuple/tuple_size.h>
|
2022-09-05 14:38:24 +02:00
|
|
|
|
2021-12-05 13:08:36 -05:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-01 20:16:40 -05:00
|
|
|
# pragma GCC system_header
|
2021-12-05 13:08:36 -05:00
|
|
|
#endif
|
|
|
|
|
2022-09-02 17:53:28 +02:00
|
|
|
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
|
2022-08-10 17:27:00 -04:00
|
|
|
# include <cstdlib>
|
2022-09-02 17:53:28 +02:00
|
|
|
# include <iosfwd>
|
2022-12-20 19:47:35 +01:00
|
|
|
# include <type_traits>
|
2022-09-02 17:53:28 +02:00
|
|
|
#endif
|
|
|
|
|
2021-04-20 12:03:32 -04:00
|
|
|
#endif // _LIBCPP_UTILITY
|