utility 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #ifndef _LIBCPP_UTILITY
  10. #define _LIBCPP_UTILITY
  11. /*
  12. utility synopsis
  13. #include <initializer_list>
  14. namespace std
  15. {
  16. template <class T>
  17. void
  18. swap(T& a, T& b);
  19. namespace rel_ops
  20. {
  21. template<class T> bool operator!=(const T&, const T&);
  22. template<class T> bool operator> (const T&, const T&);
  23. template<class T> bool operator<=(const T&, const T&);
  24. template<class T> bool operator>=(const T&, const T&);
  25. }
  26. template<class T>
  27. void
  28. swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
  29. is_nothrow_move_assignable<T>::value);
  30. template <class T, size_t N>
  31. void
  32. swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
  33. template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14
  34. template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14
  35. template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
  36. template <class T>
  37. typename conditional
  38. <
  39. !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
  40. const T&,
  41. T&&
  42. >::type
  43. move_if_noexcept(T& x) noexcept; // constexpr in C++14
  44. template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17
  45. template <class T> void as_const(const T&&) = delete; // C++17
  46. template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
  47. template<class T, class U> constexpr bool cmp_equal(T t, U u) noexcept; // C++20
  48. template<class T, class U> constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20
  49. template<class T, class U> constexpr bool cmp_less(T t, U u) noexcept; // C++20
  50. template<class T, class U> constexpr bool cmp_greater(T t, U u) noexcept; // C++20
  51. template<class T, class U> constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20
  52. template<class T, class U> constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20
  53. template<class R, class T> constexpr bool in_range(T t) noexcept; // C++20
  54. template <class T1, class T2>
  55. struct pair
  56. {
  57. typedef T1 first_type;
  58. typedef T2 second_type;
  59. T1 first;
  60. T2 second;
  61. pair(const pair&) = default;
  62. pair(pair&&) = default;
  63. explicit(see-below) constexpr pair();
  64. explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14
  65. template <class U = T1, class V = T2> explicit(see-below) pair(U&&, V&&); // constexpr in C++14
  66. template <class U, class V> explicit(see-below) pair(const pair<U, V>& p); // constexpr in C++14
  67. template <class U, class V> explicit(see-below) pair(pair<U, V>&& p); // constexpr in C++14
  68. template <class... Args1, class... Args2>
  69. pair(piecewise_construct_t, tuple<Args1...> first_args,
  70. tuple<Args2...> second_args); // constexpr in C++20
  71. template <class U, class V> pair& operator=(const pair<U, V>& p); // constexpr in C++20
  72. pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
  73. is_nothrow_move_assignable<T2>::value); // constexpr in C++20
  74. template <class U, class V> pair& operator=(pair<U, V>&& p); // constexpr in C++20
  75. void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
  76. is_nothrow_swappable_v<T2>); // constexpr in C++20
  77. };
  78. template<class T1, class T2, class U1, class U2, template<class> class TQual, template<class> class UQual>
  79. struct basic_common_reference<pair<T1, T2>, pair<U1, U2>, TQual, UQual>; // since C++23
  80. template<class T1, class T2, class U1, class U2>
  81. struct common_type<pair<T1, T2>, pair<U1, U2>>; // since C++23
  82. template<class T1, class T2> pair(T1, T2) -> pair<T1, T2>;
  83. template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
  84. template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
  85. template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
  86. template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
  87. template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
  88. template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14, removed in C++20
  89. template <class T1, class T2>
  90. constexpr common_comparison_type_t<synth-three-way-result<T1>,
  91. synth-three-way-result<T2>>
  92. operator<=>(const pair<T1,T2>&, const pair<T1,T2>&); // C++20
  93. template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
  94. template <class T1, class T2>
  95. void
  96. swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); // constexpr in C++20
  97. struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
  98. inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
  99. template <class T> struct tuple_size;
  100. template <size_t I, class T> struct tuple_element;
  101. template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
  102. template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
  103. template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
  104. template<size_t I, class T1, class T2>
  105. typename tuple_element<I, pair<T1, T2> >::type&
  106. get(pair<T1, T2>&) noexcept; // constexpr in C++14
  107. template<size_t I, class T1, class T2>
  108. const typename tuple_element<I, pair<T1, T2> >::type&
  109. get(const pair<T1, T2>&) noexcept; // constexpr in C++14
  110. template<size_t I, class T1, class T2>
  111. typename tuple_element<I, pair<T1, T2> >::type&&
  112. get(pair<T1, T2>&&) noexcept; // constexpr in C++14
  113. template<size_t I, class T1, class T2>
  114. const typename tuple_element<I, pair<T1, T2> >::type&&
  115. get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
  116. template<class T1, class T2>
  117. constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
  118. template<class T1, class T2>
  119. constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
  120. template<class T1, class T2>
  121. constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
  122. template<class T1, class T2>
  123. constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
  124. template<class T1, class T2>
  125. constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
  126. template<class T1, class T2>
  127. constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
  128. template<class T1, class T2>
  129. constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
  130. template<class T1, class T2>
  131. constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
  132. // C++14
  133. template<class T, T... I>
  134. struct integer_sequence
  135. {
  136. typedef T value_type;
  137. static constexpr size_t size() noexcept;
  138. };
  139. template<size_t... I>
  140. using index_sequence = integer_sequence<size_t, I...>;
  141. template<class T, T N>
  142. using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
  143. template<size_t N>
  144. using make_index_sequence = make_integer_sequence<size_t, N>;
  145. template<class... T>
  146. using index_sequence_for = make_index_sequence<sizeof...(T)>;
  147. template<class T, class U=T>
  148. constexpr T exchange(T& obj, U&& new_value)
  149. noexcept(is_nothrow_move_constructible<T>::value && is_nothrow_assignable<T&, U>::value); // constexpr in C++17, noexcept in C++23
  150. // 20.2.7, in-place construction // C++17
  151. struct in_place_t {
  152. explicit in_place_t() = default;
  153. };
  154. inline constexpr in_place_t in_place{};
  155. template <class T>
  156. struct in_place_type_t {
  157. explicit in_place_type_t() = default;
  158. };
  159. template <class T>
  160. inline constexpr in_place_type_t<T> in_place_type{};
  161. template <size_t I>
  162. struct in_place_index_t {
  163. explicit in_place_index_t() = default;
  164. };
  165. template <size_t I>
  166. inline constexpr in_place_index_t<I> in_place_index{};
  167. // [utility.underlying], to_underlying
  168. template <class T>
  169. constexpr underlying_type_t<T> to_underlying( T value ) noexcept; // C++2b
  170. } // std
  171. */
  172. #include <__config>
  173. #include <__debug>
  174. #include <__tuple>
  175. #include <__utility/as_const.h>
  176. #include <__utility/auto_cast.h>
  177. #include <__utility/cmp.h>
  178. #include <__utility/declval.h>
  179. #include <__utility/exchange.h>
  180. #include <__utility/forward.h>
  181. #include <__utility/in_place.h>
  182. #include <__utility/integer_sequence.h>
  183. #include <__utility/move.h>
  184. #include <__utility/pair.h>
  185. #include <__utility/piecewise_construct.h>
  186. #include <__utility/priority_tag.h>
  187. #include <__utility/rel_ops.h>
  188. #include <__utility/swap.h>
  189. #include <__utility/to_underlying.h>
  190. #include <__utility/transaction.h>
  191. #include <__utility/unreachable.h>
  192. #include <compare>
  193. #include <initializer_list>
  194. #include <version>
  195. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  196. # pragma GCC system_header
  197. #endif
  198. #endif // _LIBCPP_UTILITY