llvm-project/libcxx/include/utility

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

252 lines
9.3 KiB
Plaintext
Raw Normal View History

2010-05-12 03:42:16 +08:00
// -*- C++ -*-
//===----------------------------------------------------------------------===//
2010-05-12 03:42:16 +08: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-12 03:42:16 +08:00
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_UTILITY
#define _LIBCPP_UTILITY
/*
utility synopsis
#include <initializer_list>
2010-05-12 03:42:16 +08: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&);
}
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-12 03:42:16 +08: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
template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
2010-05-12 03:42:16 +08:00
template <class T>
typename conditional
<
!is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
2010-05-12 03:42:16 +08:00
const T&,
T&&
>::type
move_if_noexcept(T& x) noexcept; // constexpr in C++14
2010-05-12 03:42:16 +08:00
template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17
template <class T> void as_const(const T&&) = delete; // C++17
2010-05-12 03:42:16 +08:00
template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
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-12 03:42:16 +08:00
template <class T1, class T2>
struct pair
{
typedef T1 first_type;
typedef T2 second_type;
T1 first;
T2 second;
pair(const pair&) = default;
pair(pair&&) = default;
explicit(see-below) constexpr pair();
explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14
template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&); // constexpr in C++14
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
2010-05-12 03:42:16 +08:00
template <class... Args1, class... Args2>
pair(piecewise_construct_t, tuple<Args1...> first_args,
tuple<Args2...> second_args); // constexpr in C++20
2010-05-12 03:42:16 +08:00
template <class U, class V> pair& operator=(const pair<U, V>& p); // constexpr in C++20
pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
is_nothrow_move_assignable<T2>::value); // constexpr in C++20
template <class U, class V> pair& operator=(pair<U, V>&& p); // constexpr in C++20
2010-05-12 03:42:16 +08:00
void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
is_nothrow_swappable_v<T2>); // constexpr in C++20
2010-05-12 03:42:16 +08: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
[libc++] P0433R2: add the remaining deduction guides. Add deduction guides to `valarray` and `scoped_allocator_adaptor`. This largely finishes implementation of the paper: * deduction guides for other classes mentioned in the paper were implemented previously (see the list below); * deduction guides for several classes contained in the proposal (`reference_wrapper`, `lock_guard`, `scoped_lock`, `unique_lock`, `shared_lock`) were removed by [LWG2981](https://wg21.link/LWG2981). Also add deduction guides to the synopsis for the few classes (e.g. `pair`) where they were missing. The only part of the paper that isn't fully implemented after this patch is making sure certain deduction guides don't participate in overload resolution when given incorrect template parameters. List of significant commits implementing the other parts of P0433 (omitting some minor fixes): * [pair](https://github.com/llvm/llvm-project/commit/af65856eec160d163c764faad250d93357be7c83) * [basic_string](https://github.com/llvm/llvm-project/commit/6d9f750dec29e8ae5366092e64cd343dae2c7464) * [array](https://github.com/llvm/llvm-project/commit/0ca8c0895c6034615593c295dd955f29b25bf3d4) * [deque](https://github.com/llvm/llvm-project/commit/dbb6f8a8179b0604e25707b5c1b72be6164f62d9) * [forward_list](https://github.com/llvm/llvm-project/commit/e076700b7786959206acef136ecf05d54078e4e1) * [list](https://github.com/llvm/llvm-project/commit/4a227e582b2f13880ea049b29988a37a0f7c0742) * [vector](https://github.com/llvm/llvm-project/commit/df8f75479278d5ce16eede342ceb5ba2fd71460b) * [queue/stack/priority_queue](https://github.com/llvm/llvm-project/commit/5b8b8b5dce587f1e5a4a31cc24f09b18bd53ff9a) * [basic_regex](https://github.com/llvm/llvm-project/commit/edd5e29cfe9f67ec8e7e0eda12eb05e616fdeebc) * [optional](https://github.com/llvm/llvm-project/commit/f35b4bc3954f3b01051fc0848535ff784809e9e2) * [map/multimap](https://github.com/llvm/llvm-project/commit/edfe8525de1f7278f4754f2bffd47b13ec291a17) * [set/multiset](https://github.com/llvm/llvm-project/commit/e20865c387e09ea0ebd5add15c762cd5271ff65f) * [unordered_set/unordered_multiset](https://github.com/llvm/llvm-project/commit/296a80102a9b72c3eda80558fb78a3ed8849b341) * [unordered_map/unordered_multimap](https://github.com/llvm/llvm-project/commit/dfcd4384cbcac0eeb7e5cbce350f875ba4da79d5) * [function](https://github.com/llvm/llvm-project/commit/e1eabcdfad89f67ae575b0c86aa4a72d277378b4) * [tuple](https://github.com/llvm/llvm-project/commit/1308011e1b5c5382281a63dd4191a1784f8d2295) * [shared_ptr/weak_ptr](https://github.com/llvm/llvm-project/commit/83564056d4b186c9fcf016cdbb388755009f7b5a) Additional notes: * It was revision 2 of the paper that was voted into the Standard. P0433R3 is a separate paper that is not part of the Standard. * The paper also mandates removing several `make_*_searcher` functions (e.g. `make_boyer_moore_searcher`) which are currently not implemented (except in `experimental/`). * The `__cpp_lib_deduction_guides` feature test macro from the paper was accidentally omitted from the Standard. Differential Revision: https://reviews.llvm.org/D112510
2021-10-28 15:36:19 +08:00
template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
template <class T1, class T2>
constexpr common_comparison_type_t<synth-three-way-result<T1>,
synth-three-way-result<T2>>
operator<=>(const pair<T1,T2>&, const pair<T1,T2>&); // C++20
2010-05-12 03:42:16 +08:00
template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
template <class T1, class T2>
void
swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
2010-05-12 03:42:16 +08:00
struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
2010-05-12 03:42:16 +08:00
template <class T> struct tuple_size;
template <size_t I, class T> struct tuple_element;
2010-05-12 03:42:16 +08: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-12 03:42:16 +08:00
template<size_t I, class T1, class T2>
typename tuple_element<I, pair<T1, T2> >::type&
get(pair<T1, T2>&) noexcept; // constexpr in C++14
2010-05-12 03:42:16 +08: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
2010-05-12 03:42:16 +08:00
2010-11-18 03:52:17 +08:00
template<size_t I, class T1, class T2>
typename tuple_element<I, pair<T1, T2> >::type&&
get(pair<T1, T2>&&) noexcept; // constexpr in C++14
2010-11-18 03:52:17 +08: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
template<class T1, class T2>
constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
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<T1, T2>&&) noexcept; // C++14
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
// 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)>;
template<class T, class U=T>
constexpr T exchange(T& obj, U&& new_value)
noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23
// 20.2.7, in-place construction // C++17
struct in_place_t {
explicit in_place_t() = default;
};
inline constexpr in_place_t in_place{};
template <class T>
struct in_place_type_t {
explicit in_place_type_t() = default;
};
template <class T>
inline constexpr in_place_type_t<T> in_place_type{};
template <size_t I>
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{};
// [utility.underlying], to_underlying
template <class T>
constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b
2010-05-12 03:42:16 +08:00
} // std
*/
#include <__assert> // all public C++ headers provide the assertion handler
2010-05-12 03:42:16 +08:00
#include <__config>
#include <__tuple>
#include <__utility/as_const.h>
#include <__utility/auto_cast.h>
#include <__utility/cmp.h>
#include <__utility/declval.h>
#include <__utility/exchange.h>
#include <__utility/forward.h>
#include <__utility/in_place.h>
#include <__utility/integer_sequence.h>
#include <__utility/move.h>
#include <__utility/pair.h>
#include <__utility/piecewise_construct.h>
#include <__utility/priority_tag.h>
#include <__utility/rel_ops.h>
#include <__utility/swap.h>
#include <__utility/to_underlying.h>
#include <__utility/transaction.h>
#include <__utility/unreachable.h>
#include <compare>
#include <initializer_list>
#include <version>
2010-05-12 03:42:16 +08:00
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
#endif // _LIBCPP_UTILITY