// -*- C++ -*- //===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_UTILITY #define _LIBCPP_UTILITY /* utility synopsis #include namespace std { template void swap(T& a, T& b); namespace rel_ops { template bool operator!=(const T&, const T&); template bool operator> (const T&, const T&); template bool operator<=(const T&, const T&); template bool operator>=(const T&, const T&); } template void swap(T& a, T& b) noexcept(is_nothrow_move_constructible::value && is_nothrow_move_assignable::value); template void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); template T&& forward(typename remove_reference::type& t) noexcept; // constexpr in C++14 template T&& forward(typename remove_reference::type&& t) noexcept; // constexpr in C++14 template [[nodiscard]] constexpr auto forward_like(auto&& x) noexcept -> see below; // since C++23 template typename remove_reference::type&& move(T&&) noexcept; // constexpr in C++14 template typename conditional < !is_nothrow_move_constructible::value && is_copy_constructible::value, const T&, T&& >::type move_if_noexcept(T& x) noexcept; // constexpr in C++14 template constexpr add_const_t& as_const(T& t) noexcept; // C++17 template void as_const(const T&&) = delete; // C++17 template typename add_rvalue_reference::type declval() noexcept; template constexpr bool cmp_equal(T t, U u) noexcept; // C++20 template constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20 template constexpr bool cmp_less(T t, U u) noexcept; // C++20 template constexpr bool cmp_greater(T t, U u) noexcept; // C++20 template constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20 template constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20 template constexpr bool in_range(T t) noexcept; // C++20 template 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 explicit(see-below) pair(U&&, V&&); // constexpr in C++14 template constexpr explicit(see below) pair(pair&); // since C++23 template explicit(see-below) pair(const pair& p); // constexpr in C++14 template explicit(see-below) pair(pair&& p); // constexpr in C++14 template constexpr explicit(see below) pair(const pair&&); // since C++23 template pair(piecewise_construct_t, tuple first_args, tuple second_args); // constexpr in C++20 constexpr const pair& operator=(const pair& p) const; // since C++23 template pair& operator=(const pair& p); // constexpr in C++20 template constexpr const pair& operator=(const pair& p) const; // since C++23 pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable::value && is_nothrow_move_assignable::value); // constexpr in C++20 constexpr const pair& operator=(pair&& p) const; // since C++23 template pair& operator=(pair&& p); // constexpr in C++20 template constexpr const pair& operator=(pair&& p) const; // since C++23 void swap(pair& p) noexcept(is_nothrow_swappable_v && is_nothrow_swappable_v); // constexpr in C++20 constexpr void swap(const pair& p) const noexcept(see below); // since C++23 }; template class TQual, template class UQual> struct basic_common_reference, pair, TQual, UQual>; // since C++23 template struct common_type, pair>; // since C++23 template pair(T1, T2) -> pair; template bool operator==(const pair&, const pair&); // constexpr in C++14 template bool operator!=(const pair&, const pair&); // constexpr in C++14, removed in C++20 template bool operator< (const pair&, const pair&); // constexpr in C++14, removed in C++20 template bool operator> (const pair&, const pair&); // constexpr in C++14, removed in C++20 template bool operator>=(const pair&, const pair&); // constexpr in C++14, removed in C++20 template bool operator<=(const pair&, const pair&); // constexpr in C++14, removed in C++20 template constexpr common_comparison_type_t, synth-three-way-result> operator<=>(const pair&, const pair&); // C++20 template pair make_pair(T1&&, T2&&); // constexpr in C++14 template void swap(pair& x, pair& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20 template constexpr void swap(const pair& x, const pair& y) noexcept(noexcept(x.swap(y))); // since C++23 struct piecewise_construct_t { explicit piecewise_construct_t() = default; }; inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); template struct tuple_size; template struct tuple_element; template struct tuple_size >; template struct tuple_element<0, pair >; template struct tuple_element<1, pair >; template typename tuple_element >::type& get(pair&) noexcept; // constexpr in C++14 template const typename tuple_element >::type& get(const pair&) noexcept; // constexpr in C++14 template typename tuple_element >::type&& get(pair&&) noexcept; // constexpr in C++14 template const typename tuple_element >::type&& get(const pair&&) noexcept; // constexpr in C++14 template constexpr T1& get(pair&) noexcept; // C++14 template constexpr const T1& get(const pair&) noexcept; // C++14 template constexpr T1&& get(pair&&) noexcept; // C++14 template constexpr const T1&& get(const pair&&) noexcept; // C++14 template constexpr T1& get(pair&) noexcept; // C++14 template constexpr const T1& get(const pair&) noexcept; // C++14 template constexpr T1&& get(pair&&) noexcept; // C++14 template constexpr const T1&& get(const pair&&) noexcept; // C++14 // C++14 template struct integer_sequence { typedef T value_type; static constexpr size_t size() noexcept; }; template using index_sequence = integer_sequence; template using make_integer_sequence = integer_sequence; template using make_index_sequence = make_integer_sequence; template using index_sequence_for = make_index_sequence; template constexpr T exchange(T& obj, U&& new_value) noexcept(is_nothrow_move_constructible::value && is_nothrow_assignable::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 struct in_place_type_t { explicit in_place_type_t() = default; }; template inline constexpr in_place_type_t in_place_type{}; template struct in_place_index_t { explicit in_place_index_t() = default; }; template inline constexpr in_place_index_t in_place_index{}; // [utility.underlying], to_underlying template constexpr underlying_type_t to_underlying( T value ) noexcept; // C++2b } // std */ #include <__assert> // all public C++ headers provide the assertion handler #include <__config> #include <__utility/as_const.h> #include <__utility/auto_cast.h> #include <__utility/cmp.h> #include <__utility/declval.h> #include <__utility/exception_guard.h> #include <__utility/exchange.h> #include <__utility/forward.h> #include <__utility/forward_like.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/unreachable.h> #include // standard-mandated includes // [utility.syn] #include #include // [tuple.helper] #include <__tuple_dir/tuple_element.h> #include <__tuple_dir/tuple_size.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 # include # include # include #endif #endif // _LIBCPP_UTILITY