brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.8 KiB · bc4eaf6 Raw
319 lines · plain
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_UTILITY11#define _LIBCPP_UTILITY12 13/*14    utility synopsis15 16#include <initializer_list>17 18namespace std19{20 21template <class T>22    void23    swap(T& a, T& b);24 25namespace rel_ops26{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>34void35swap(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>39void40swap(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++1443template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++1444 45template <typename T>46[[nodiscard]] constexpr47auto forward_like(auto&& x) noexcept -> see below;                               // since C++2348 49template <class T> typename remove_reference<T>::type&& move(T&&) noexcept;      // constexpr in C++1450 51template <class T>52    typename conditional53    <54        !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,55        const T&,56        T&&57    >::type58    move_if_noexcept(T& x) noexcept; // constexpr in C++1459 60template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept;      // C++1761template <class T>                      void as_const(const T&&) = delete; // C++1762 63template <class T> typename add_rvalue_reference<T>::type declval() noexcept;64 65template<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept;         // C++2066template<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept;     // C++2067template<class T, class U> constexpr bool cmp_less(T t, U u) noexcept;          // C++2068template<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept;       // C++2069template<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept;    // C++2070template<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++2071template<class R, class T> constexpr bool in_range(T t) noexcept;               // C++2072 73template <class T1, class T2>74struct pair75{76    typedef T1 first_type;77    typedef T2 second_type;78 79    T1 first;80    T2 second;81 82    pair(const pair&) = default;83    pair(pair&&) = default;84    explicit(see-below) constexpr pair();85    explicit(see-below) pair(const T1& x, const T2& y);                          // constexpr in C++1486    template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&);    // constexpr in C++1487    template <class U, class V> constexpr explicit(see-below) pair(pair<U, V>&); // since C++2388    template <class U, class V> explicit(see-below) pair(const pair<U, V>& p);   // constexpr in C++1489    template <class U, class V> explicit(see-below) pair(pair<U, V>&& p);        // constexpr in C++1490    template <class U, class V>91    constexpr explicit(see-below) pair(const pair<U, V>&&);                      // since C++2392    template <pair-like P> constexpr explicit(see-below) pair(P&&);              // since C++2393    template <class... Args1, class... Args2>94        pair(piecewise_construct_t, tuple<Args1...> first_args,                  // constexpr in C++2095                                    tuple<Args2...> second_args);96 97    constexpr const pair& operator=(const pair& p) const;                        // since C++2398    template <class U, class V> pair& operator=(const pair<U, V>& p);            // constexpr in C++2099    template <class U, class V>100    constexpr const pair& operator=(const pair<U, V>& p) const;                  // since C++23101    pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&102                                       is_nothrow_move_assignable<T2>::value);   // constexpr in C++20103    constexpr const pair& operator=(pair&& p) const;                             // since C++23104    template <class U, class V> pair& operator=(pair<U, V>&& p);                 // constexpr in C++20105    template <class U, class V>106    constexpr const pair& operator=(pair<U, V>&& p) const;                       // since C++23107    template <pair-like P> constexpr pair& operator=(P&&);                       // since C++23108    template <pair-like P> constexpr const pair& operator=(P&&) const;           // since C++23109 110    void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&111                                is_nothrow_swappable_v<T2>);                     // constexpr in C++20112    constexpr void swap(const pair& p) const noexcept(see below);                // since C++23113};114 115template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual>116struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>;         // since C++23117 118template<class T1, class T2, class U1, class U2>119struct common_type<pair<T1, T2>, pair<U1, U2>>;                                  // since C++23120 121template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;122 123template <class T1, class T2, class U1, class U2>124bool operator==(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14125template <class T1, class T2, class U1, class U2>126bool operator!=(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20127template <class T1, class T2, class U1, class U2>128bool operator< (const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20129template <class T1, class T2, class U1, class U2>130bool operator> (const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20131template <class T1, class T2, class U1, class U2>132bool operator>=(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20133template <class T1, class T2, class U1, class U2>134bool operator<=(const pair<T1,T2>&, const pair<U1,U2>&);                         // constexpr in C++14, removed in C++20135template <class T1, class T2, class U1, class U2>136  constexpr common_comparison_type_t<synth-three-way-result<T1,U1>,137                                     synth-three-way-result<T2,U2>>138    operator<=>(const pair<T1,T2>&, const pair<U1,U2>&);                         // C++20139 140template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&);                // constexpr in C++14141template <class T1, class T2>142void143swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));            // constexpr in C++20144 145template<class T1, class T2>                                                     // since C++23146constexpr void swap(const pair<T1, T2>& x, const pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));147 148struct piecewise_construct_t { explicit piecewise_construct_t() = default; };149inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();150 151template <class T> struct tuple_size;152template <size_t I, class T> struct tuple_element;153 154template <class T1, class T2> struct tuple_size<pair<T1, T2> >;155template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;156template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;157 158template<size_t I, class T1, class T2>159    typename tuple_element<I, pair<T1, T2> >::type&160    get(pair<T1, T2>&) noexcept; // constexpr in C++14161 162template<size_t I, class T1, class T2>163    const typename tuple_element<I, pair<T1, T2> >::type&164    get(const pair<T1, T2>&) noexcept; // constexpr in C++14165 166template<size_t I, class T1, class T2>167    typename tuple_element<I, pair<T1, T2> >::type&&168    get(pair<T1, T2>&&) noexcept; // constexpr in C++14169 170template<size_t I, class T1, class T2>171    const typename tuple_element<I, pair<T1, T2> >::type&&172    get(const pair<T1, T2>&&) noexcept; // constexpr in C++14173 174template<class T1, class T2>175    constexpr T1& get(pair<T1, T2>&) noexcept; // C++14176 177template<class T1, class T2>178    constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14179 180template<class T1, class T2>181    constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14182 183template<class T1, class T2>184    constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14185 186template<class T1, class T2>187    constexpr T1& get(pair<T2, T1>&) noexcept; // C++14188 189template<class T1, class T2>190    constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14191 192template<class T1, class T2>193    constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14194 195template<class T1, class T2>196    constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14197 198// C++14199 200template<class T, T... I>201struct integer_sequence202{203    typedef T value_type;204 205    static constexpr size_t size() noexcept;206};207 208template<size_t... I>209  using index_sequence = integer_sequence<size_t, I...>;210 211template<class T, T N>212  using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;213template<size_t N>214  using make_index_sequence = make_integer_sequence<size_t, N>;215 216template<class... T>217  using index_sequence_for = make_index_sequence<sizeof...(T)>;218 219template<class T, class U=T>220    constexpr T exchange(T& obj, U&& new_value)                                 // constexpr in C++17, noexcept in C++23221      noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value);222 223// 20.2.7, in-place construction // C++17224struct in_place_t {225  explicit in_place_t() = default;226};227inline constexpr in_place_t in_place{};228template <class T>229  struct in_place_type_t {230    explicit in_place_type_t() = default;231  };232template <class T>233  inline constexpr in_place_type_t<T> in_place_type{};234template <size_t I>235  struct in_place_index_t {236    explicit in_place_index_t() = default;237  };238template <size_t I>239  inline constexpr in_place_index_t<I> in_place_index{};240 241// [utility.underlying], to_underlying242template <class T>243    constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++23244 245}  // std246 247*/248 249#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)250#  include <__cxx03/utility>251#else252#  include <__config>253 254#  include <__utility/declval.h>255#  include <__utility/forward.h>256#  include <__utility/move.h>257#  include <__utility/pair.h>258#  include <__utility/piecewise_construct.h>259#  include <__utility/rel_ops.h>260#  include <__utility/swap.h>261 262#  if _LIBCPP_STD_VER >= 14263#    include <__utility/exchange.h>264#    include <__utility/integer_sequence.h>265#  endif266 267#  if _LIBCPP_STD_VER >= 17268#    include <__utility/as_const.h>269#    include <__utility/in_place.h>270#  endif271 272#  if _LIBCPP_STD_VER >= 20273#    include <__utility/cmp.h>274#  endif275 276#  if _LIBCPP_STD_VER >= 23277#    include <__utility/forward_like.h>278#    include <__utility/to_underlying.h>279#    include <__utility/unreachable.h>280#  endif281 282#  if _LIBCPP_STD_VER >= 26283#    include <__variant/monostate.h>284#  endif285 286#  include <version>287 288// standard-mandated includes289 290// [utility.syn]291#  include <compare>292#  include <initializer_list>293 294// [tuple.creation]295 296#  include <__tuple/ignore.h>297 298// [tuple.helper]299#  include <__tuple/tuple_element.h>300#  include <__tuple/tuple_size.h>301 302#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)303#    pragma GCC system_header304#  endif305 306#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20307#    include <limits>308#  endif309 310#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20311#    include <cstddef>312#    include <cstdlib>313#    include <iosfwd>314#    include <type_traits>315#  endif316#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)317 318#endif // _LIBCPP_UTILITY319