Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- utility -----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_UTILITY |
| 12 | #define _LIBCPP_UTILITY |
| 13 | |
| 14 | /* |
| 15 | utility synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class T> |
| 21 | void |
| 22 | swap(T& a, T& b); |
| 23 | |
| 24 | namespace rel_ops |
| 25 | { |
| 26 | template<class T> bool operator!=(const T&, const T&); |
| 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 | } |
| 31 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 32 | template<class T> |
| 33 | void |
| 34 | swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && |
| 35 | is_nothrow_move_assignable<T>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 37 | template <class T, size_t N> |
| 38 | void |
| 39 | swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); |
| 40 | |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 41 | template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 |
| 42 | template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 43 | |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 44 | template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | |
| 46 | template <class T> |
| 47 | typename conditional |
| 48 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 49 | !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 50 | const T&, |
| 51 | T&& |
| 52 | >::type |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 53 | move_if_noexcept(T& x) noexcept; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | |
Marshall Clow | f60d092 | 2015-11-17 00:08:08 +0000 | [diff] [blame] | 55 | template <class T> constexpr add_const<T>_t& as_const(T& t) noexcept; // C++17 |
| 56 | template <class T> void as_const(const T&&) = delete; // C++17 |
| 57 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | template <class T> typename add_rvalue_reference<T>::type declval() noexcept; |
| 59 | |
| 60 | template <class T1, class T2> |
| 61 | struct pair |
| 62 | { |
| 63 | typedef T1 first_type; |
| 64 | typedef T2 second_type; |
| 65 | |
| 66 | T1 first; |
| 67 | T2 second; |
| 68 | |
| 69 | pair(const pair&) = default; |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 70 | pair(pair&&) = default; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 | constexpr pair(); |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 72 | pair(const T1& x, const T2& y); // constexpr in C++14 |
| 73 | template <class U, class V> pair(U&& x, V&& y); // constexpr in C++14 |
| 74 | template <class U, class V> pair(const pair<U, V>& p); // constexpr in C++14 |
| 75 | template <class U, class V> pair(pair<U, V>&& p); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | template <class... Args1, class... Args2> |
| 77 | pair(piecewise_construct_t, tuple<Args1...> first_args, |
| 78 | tuple<Args2...> second_args); |
| 79 | |
| 80 | template <class U, class V> pair& operator=(const pair<U, V>& p); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 81 | pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && |
| 82 | is_nothrow_move_assignable<T2>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 83 | template <class U, class V> pair& operator=(pair<U, V>&& p); |
| 84 | |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 85 | void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> && |
| 86 | is_nothrow_swappable_v<T2>); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 89 | template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 |
| 90 | template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 |
| 91 | template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 |
| 92 | template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 |
| 93 | template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 |
| 94 | template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 96 | template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 97 | template <class T1, class T2> |
| 98 | void |
| 99 | swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 100 | |
| 101 | struct piecewise_construct_t { }; |
| 102 | constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); |
| 103 | |
| 104 | template <class T> class tuple_size; |
| 105 | template <size_t I, class T> class tuple_element; |
| 106 | |
Marshall Clow | 50fe0c7 | 2014-03-03 06:18:11 +0000 | [diff] [blame] | 107 | template <class T1, class T2> struct tuple_size<pair<T1, T2> >; |
| 108 | template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; |
| 109 | template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 110 | |
| 111 | template<size_t I, class T1, class T2> |
Marshall Clow | 50fe0c7 | 2014-03-03 06:18:11 +0000 | [diff] [blame] | 112 | typename tuple_element<I, pair<T1, T2> >::type& |
| 113 | get(pair<T1, T2>&) noexcept; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 114 | |
| 115 | template<size_t I, class T1, class T2> |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 116 | const typename tuple_element<I, pair<T1, T2> >::type& |
Marshall Clow | 50fe0c7 | 2014-03-03 06:18:11 +0000 | [diff] [blame] | 117 | get(const pair<T1, T2>&) noexcept; // constexpr in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 118 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 119 | template<size_t I, class T1, class T2> |
Marshall Clow | 50fe0c7 | 2014-03-03 06:18:11 +0000 | [diff] [blame] | 120 | typename tuple_element<I, pair<T1, T2> >::type&& |
| 121 | get(pair<T1, T2>&&) noexcept; // constexpr in C++14 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 122 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 123 | template<size_t I, class T1, class T2> |
| 124 | const typename tuple_element<I, pair<T1, T2> >::type&& |
| 125 | get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 |
| 126 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 127 | template<class T1, class T2> |
Marshall Clow | 50fe0c7 | 2014-03-03 06:18:11 +0000 | [diff] [blame] | 128 | constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 129 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 130 | template<class T1, class T2> |
Marshall Clow | a660757 | 2015-11-19 19:45:29 +0000 | [diff] [blame] | 131 | constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 132 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 133 | template<class T1, class T2> |
Marshall Clow | 50fe0c7 | 2014-03-03 06:18:11 +0000 | [diff] [blame] | 134 | constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 135 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 136 | template<class T1, class T2> |
| 137 | constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 |
| 138 | |
| 139 | template<class T1, class T2> |
| 140 | constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 |
| 141 | |
| 142 | template<class T1, class T2> |
| 143 | constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 |
| 144 | |
| 145 | template<class T1, class T2> |
| 146 | constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 |
| 147 | |
| 148 | template<class T1, class T2> |
| 149 | constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 |
| 150 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 151 | // C++14 |
| 152 | |
| 153 | template<class T, T... I> |
| 154 | struct integer_sequence |
| 155 | { |
| 156 | typedef T value_type; |
| 157 | |
| 158 | static constexpr size_t size() noexcept; |
| 159 | }; |
| 160 | |
| 161 | template<size_t... I> |
| 162 | using index_sequence = integer_sequence<size_t, I...>; |
| 163 | |
| 164 | template<class T, T N> |
| 165 | using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; |
| 166 | template<size_t N> |
| 167 | using make_index_sequence = make_integer_sequence<size_t, N>; |
| 168 | |
| 169 | template<class... T> |
| 170 | using index_sequence_for = make_index_sequence<sizeof...(T)>; |
| 171 | |
Marshall Clow | 5270a84 | 2016-06-19 19:29:52 +0000 | [diff] [blame] | 172 | template<class T, class U=T> |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 173 | T exchange(T& obj, U&& new_value); |
Eric Fiselier | eef85d9 | 2016-07-23 22:19:19 +0000 | [diff] [blame^] | 174 | |
| 175 | // 20.2.7, in-place construction // C++17 |
| 176 | struct in_place_tag { in_place_tag() = delete; }; // C++17 |
| 177 | using in_place_t = in_place_tag(&)(unspecified ); |
| 178 | template <class T> |
| 179 | using in_place_type_t = in_place_tag(&)(unspecified <T>); |
| 180 | template <size_t I> |
| 181 | using in_place_index_t = in_place_tag(&)(unspecified <I>); |
| 182 | in_place_tag in_place(unspecified ); |
| 183 | template <class T> |
| 184 | in_place_tag in_place(unspecified <T>); |
| 185 | template <size_t I> |
| 186 | in_place_tag in_place(unspecified <I>); |
| 187 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 188 | } // std |
| 189 | |
| 190 | */ |
| 191 | |
| 192 | #include <__config> |
| 193 | #include <__tuple> |
| 194 | #include <type_traits> |
Ben Craig | d59d416 | 2016-04-19 20:13:55 +0000 | [diff] [blame] | 195 | #include <initializer_list> |
Eric Fiselier | eef85d9 | 2016-07-23 22:19:19 +0000 | [diff] [blame^] | 196 | #include <__debug> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 197 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 198 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 199 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 200 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | |
| 202 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 203 | |
| 204 | namespace rel_ops |
| 205 | { |
| 206 | |
| 207 | template<class _Tp> |
| 208 | inline _LIBCPP_INLINE_VISIBILITY |
| 209 | bool |
| 210 | operator!=(const _Tp& __x, const _Tp& __y) |
| 211 | { |
| 212 | return !(__x == __y); |
| 213 | } |
| 214 | |
| 215 | template<class _Tp> |
| 216 | inline _LIBCPP_INLINE_VISIBILITY |
| 217 | bool |
| 218 | operator> (const _Tp& __x, const _Tp& __y) |
| 219 | { |
| 220 | return __y < __x; |
| 221 | } |
| 222 | |
| 223 | template<class _Tp> |
| 224 | inline _LIBCPP_INLINE_VISIBILITY |
| 225 | bool |
| 226 | operator<=(const _Tp& __x, const _Tp& __y) |
| 227 | { |
| 228 | return !(__y < __x); |
| 229 | } |
| 230 | |
| 231 | template<class _Tp> |
| 232 | inline _LIBCPP_INLINE_VISIBILITY |
| 233 | bool |
| 234 | operator>=(const _Tp& __x, const _Tp& __y) |
| 235 | { |
| 236 | return !(__x < __y); |
| 237 | } |
| 238 | |
| 239 | } // rel_ops |
| 240 | |
| 241 | // swap_ranges |
| 242 | |
Marshall Clow | fd8ed7f | 2015-01-06 19:20:49 +0000 | [diff] [blame] | 243 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 244 | template <class _ForwardIterator1, class _ForwardIterator2> |
| 245 | inline _LIBCPP_INLINE_VISIBILITY |
| 246 | _ForwardIterator2 |
| 247 | swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) |
| 248 | { |
Eric Fiselier | b991975 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 249 | for(; __first1 != __last1; ++__first1, (void) ++__first2) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | swap(*__first1, *__first2); |
| 251 | return __first2; |
| 252 | } |
| 253 | |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 254 | // forward declared in <type_traits> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 255 | template<class _Tp, size_t _Np> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 256 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 257 | typename enable_if< |
| 258 | __is_swappable<_Tp>::value |
| 259 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 260 | swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 261 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 262 | _VSTD::swap_ranges(__a, __a + _Np, __b); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | template <class _Tp> |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 266 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 267 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | typename conditional |
| 269 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 270 | !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 271 | const _Tp&, |
| 272 | _Tp&& |
| 273 | >::type |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 274 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | const _Tp& |
| 276 | #endif |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 277 | move_if_noexcept(_Tp& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 279 | return _VSTD::move(__x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Marshall Clow | f60d092 | 2015-11-17 00:08:08 +0000 | [diff] [blame] | 282 | #if _LIBCPP_STD_VER > 14 |
| 283 | template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } |
| 284 | template <class _Tp> void as_const(const _Tp&&) = delete; |
| 285 | #endif |
| 286 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 287 | struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { }; |
Howard Hinnant | 616e92d | 2012-04-03 23:45:46 +0000 | [diff] [blame] | 288 | #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 289 | extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); |
Howard Hinnant | 2a5349b | 2012-04-03 21:09:48 +0000 | [diff] [blame] | 290 | #else |
| 291 | constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); |
| 292 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 295 | struct _LIBCPP_TYPE_VIS_ONLY pair |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 296 | { |
| 297 | typedef _T1 first_type; |
| 298 | typedef _T2 second_type; |
| 299 | |
| 300 | _T1 first; |
| 301 | _T2 second; |
| 302 | |
Eric Fiselier | 9bef1ff | 2015-12-23 08:20:26 +0000 | [diff] [blame] | 303 | #ifndef _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS |
| 304 | template <bool _Dummy = true, class = typename enable_if< |
| 305 | __dependent_type<is_default_constructible<_T1>, _Dummy>::value && |
| 306 | __dependent_type<is_default_constructible<_T2>, _Dummy>::value |
| 307 | >::type> |
| 308 | #endif |
Howard Hinnant | 2a5349b | 2012-04-03 21:09:48 +0000 | [diff] [blame] | 309 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 310 | |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 311 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 312 | pair(const _T1& __x, const _T2& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 313 | : first(__x), second(__y) {} |
| 314 | |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 315 | template<class _U1, class _U2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 316 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 9c59d38 | 2011-07-27 19:25:28 +0000 | [diff] [blame] | 317 | pair(const pair<_U1, _U2>& __p |
| 318 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 319 | ,typename enable_if<is_convertible<const _U1&, _T1>::value && |
| 320 | is_convertible<const _U2&, _T2>::value>::type* = 0 |
Howard Hinnant | 9c59d38 | 2011-07-27 19:25:28 +0000 | [diff] [blame] | 321 | #endif |
| 322 | ) |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 323 | : first(__p.first), second(__p.second) {} |
| 324 | |
Eric Fiselier | c71c304 | 2016-07-18 01:58:37 +0000 | [diff] [blame] | 325 | #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) |
Eric Fiselier | d9e1819 | 2016-06-14 14:34:19 +0000 | [diff] [blame] | 326 | _LIBCPP_INLINE_VISIBILITY |
| 327 | pair(const pair& __p) |
| 328 | _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && |
| 329 | is_nothrow_copy_constructible<second_type>::value) |
| 330 | : first(__p.first), |
| 331 | second(__p.second) |
| 332 | { |
| 333 | } |
Eric Fiselier | c71c304 | 2016-07-18 01:58:37 +0000 | [diff] [blame] | 334 | |
| 335 | # ifndef _LIBCPP_CXX03_LANG |
| 336 | _LIBCPP_INLINE_VISIBILITY |
| 337 | pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value && |
| 338 | is_nothrow_move_constructible<second_type>::value) |
| 339 | : first(_VSTD::forward<first_type>(__p.first)), |
| 340 | second(_VSTD::forward<second_type>(__p.second)) |
| 341 | { |
| 342 | } |
| 343 | # endif |
| 344 | #elif !defined(_LIBCPP_CXX03_LANG) |
| 345 | pair(pair const&) = default; |
| 346 | pair(pair&&) = default; |
| 347 | #else |
| 348 | // Use the implicitly declared copy constructor in C++03 |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 349 | #endif |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 350 | |
| 351 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 352 | pair& operator=(const pair& __p) |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 353 | _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && |
| 354 | is_nothrow_copy_assignable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 355 | { |
| 356 | first = __p.first; |
| 357 | second = __p.second; |
| 358 | return *this; |
| 359 | } |
| 360 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 361 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | |
| 363 | template <class _U1, class _U2, |
Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 364 | class = typename enable_if<is_convertible<_U1, first_type>::value && |
| 365 | is_convertible<_U2, second_type>::value>::type> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 366 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 367 | pair(_U1&& __u1, _U2&& __u2) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 368 | : first(_VSTD::forward<_U1>(__u1)), |
| 369 | second(_VSTD::forward<_U2>(__u2)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | {} |
| 371 | |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 372 | template<class _U1, class _U2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 373 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 374 | pair(pair<_U1, _U2>&& __p, |
Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 375 | typename enable_if<is_convertible<_U1, _T1>::value && |
| 376 | is_convertible<_U2, _T2>::value>::type* = 0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 377 | : first(_VSTD::forward<_U1>(__p.first)), |
| 378 | second(_VSTD::forward<_U2>(__p.second)) {} |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 379 | |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 380 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 381 | pair& |
| 382 | operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && |
| 383 | is_nothrow_move_assignable<second_type>::value) |
| 384 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 385 | first = _VSTD::forward<first_type>(__p.first); |
| 386 | second = _VSTD::forward<second_type>(__p.second); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 387 | return *this; |
| 388 | } |
| 389 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 390 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 391 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 | template<class _Tuple, |
| 393 | class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 394 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | pair(_Tuple&& __p) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 396 | : first(_VSTD::forward<typename tuple_element<0, |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 397 | typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 398 | second(_VSTD::forward<typename tuple_element<1, |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 399 | typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 400 | {} |
| 401 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 402 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 403 | |
Howard Hinnant | 6cc99fa | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 404 | template <class... _Args1, class... _Args2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 405 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 407 | tuple<_Args2...> __second_args) |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 408 | : pair(__pc, __first_args, __second_args, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | typename __make_tuple_indices<sizeof...(_Args1)>::type(), |
| 410 | typename __make_tuple_indices<sizeof...(_Args2) >::type()) |
| 411 | {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 412 | |
| 413 | template <class _Tuple, |
| 414 | class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 415 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | pair& |
| 417 | operator=(_Tuple&& __p) |
| 418 | { |
| 419 | typedef typename __make_tuple_types<_Tuple>::type _TupleRef; |
| 420 | typedef typename tuple_element<0, _TupleRef>::type _U0; |
| 421 | typedef typename tuple_element<1, _TupleRef>::type _U1; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 422 | first = _VSTD::forward<_U0>(_VSTD::get<0>(__p)); |
| 423 | second = _VSTD::forward<_U1>(_VSTD::get<1>(__p)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | return *this; |
| 425 | } |
| 426 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 427 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 428 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 429 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 430 | _LIBCPP_INLINE_VISIBILITY |
| 431 | void |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 432 | swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && |
| 433 | __is_nothrow_swappable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 434 | { |
Marshall Clow | 6b0e419 | 2015-09-22 17:50:11 +0000 | [diff] [blame] | 435 | using _VSTD::swap; |
| 436 | swap(first, __p.first); |
| 437 | swap(second, __p.second); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 438 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 440 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 442 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
Howard Hinnant | 5f5859c | 2011-01-13 20:05:05 +0000 | [diff] [blame] | 443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 | pair(piecewise_construct_t, |
| 445 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 446 | __tuple_indices<_I1...>, __tuple_indices<_I2...>); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 447 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 451 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 452 | bool |
| 453 | operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 454 | { |
| 455 | return __x.first == __y.first && __x.second == __y.second; |
| 456 | } |
| 457 | |
| 458 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 459 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 460 | bool |
| 461 | operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 462 | { |
| 463 | return !(__x == __y); |
| 464 | } |
| 465 | |
| 466 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 467 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 468 | bool |
| 469 | operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 470 | { |
| 471 | return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); |
| 472 | } |
| 473 | |
| 474 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 475 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | bool |
| 477 | operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 478 | { |
| 479 | return __y < __x; |
| 480 | } |
| 481 | |
| 482 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 483 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 484 | bool |
| 485 | operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 486 | { |
| 487 | return !(__x < __y); |
| 488 | } |
| 489 | |
| 490 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 491 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | bool |
| 493 | operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 494 | { |
| 495 | return !(__y < __x); |
| 496 | } |
| 497 | |
| 498 | template <class _T1, class _T2> |
| 499 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 500 | typename enable_if |
| 501 | < |
| 502 | __is_swappable<_T1>::value && |
| 503 | __is_swappable<_T2>::value, |
| 504 | void |
| 505 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 506 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 507 | _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && |
| 508 | __is_nothrow_swappable<_T2>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 509 | { |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 510 | __x.swap(__y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 513 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | |
| 516 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 517 | struct __make_pair_return_impl |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | { |
| 519 | typedef _Tp type; |
| 520 | }; |
| 521 | |
| 522 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 523 | struct __make_pair_return_impl<reference_wrapper<_Tp>> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | { |
| 525 | typedef _Tp& type; |
| 526 | }; |
| 527 | |
| 528 | template <class _Tp> |
| 529 | struct __make_pair_return |
| 530 | { |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 531 | typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 535 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 536 | pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 537 | make_pair(_T1&& __t1, _T2&& __t2) |
| 538 | { |
| 539 | return pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 540 | (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 543 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 544 | |
| 545 | template <class _T1, class _T2> |
| 546 | inline _LIBCPP_INLINE_VISIBILITY |
| 547 | pair<_T1,_T2> |
| 548 | make_pair(_T1 __x, _T2 __y) |
| 549 | { |
| 550 | return pair<_T1, _T2>(__x, __y); |
| 551 | } |
| 552 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 553 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 555 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 556 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 557 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | |
| 559 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 560 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | { |
| 562 | public: |
| 563 | typedef _T1 type; |
| 564 | }; |
| 565 | |
| 566 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 567 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 568 | { |
| 569 | public: |
| 570 | typedef _T2 type; |
| 571 | }; |
| 572 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 573 | template <size_t _Ip> struct __get_pair; |
| 574 | |
| 575 | template <> |
| 576 | struct __get_pair<0> |
| 577 | { |
| 578 | template <class _T1, class _T2> |
| 579 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 580 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 582 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 583 | |
| 584 | template <class _T1, class _T2> |
| 585 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 586 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 587 | const _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 588 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 589 | |
| 590 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 591 | |
| 592 | template <class _T1, class _T2> |
| 593 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 594 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 595 | _T1&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 596 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 597 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 598 | template <class _T1, class _T2> |
| 599 | static |
| 600 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 601 | const _T1&& |
| 602 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);} |
| 603 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 604 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | }; |
| 606 | |
| 607 | template <> |
| 608 | struct __get_pair<1> |
| 609 | { |
| 610 | template <class _T1, class _T2> |
| 611 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 612 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 614 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 615 | |
| 616 | template <class _T1, class _T2> |
| 617 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 618 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | const _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 620 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 621 | |
| 622 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 623 | |
| 624 | template <class _T1, class _T2> |
| 625 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 626 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 627 | _T2&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 628 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 629 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 630 | template <class _T1, class _T2> |
| 631 | static |
| 632 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 633 | const _T2&& |
| 634 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);} |
| 635 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 636 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | }; |
| 638 | |
| 639 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 640 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 641 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 642 | get(pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | { |
| 644 | return __get_pair<_Ip>::get(__p); |
| 645 | } |
| 646 | |
| 647 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 648 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 649 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 650 | get(const pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 651 | { |
| 652 | return __get_pair<_Ip>::get(__p); |
| 653 | } |
| 654 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 655 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 656 | |
| 657 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 658 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 659 | typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 660 | get(pair<_T1, _T2>&& __p) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 661 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 662 | return __get_pair<_Ip>::get(_VSTD::move(__p)); |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 665 | template <size_t _Ip, class _T1, class _T2> |
| 666 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 667 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
| 668 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT |
| 669 | { |
| 670 | return __get_pair<_Ip>::get(_VSTD::move(__p)); |
| 671 | } |
| 672 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 673 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 674 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 675 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 676 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 677 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 678 | constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT |
| 679 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 680 | return __get_pair<0>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 684 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 685 | constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT |
| 686 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 687 | return __get_pair<0>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 691 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 692 | constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT |
| 693 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 694 | return __get_pair<0>::get(_VSTD::move(__p)); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 698 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 699 | constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT |
| 700 | { |
| 701 | return __get_pair<0>::get(_VSTD::move(__p)); |
| 702 | } |
| 703 | |
| 704 | template <class _T1, class _T2> |
| 705 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 706 | constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT |
| 707 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 708 | return __get_pair<1>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 712 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 713 | constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT |
| 714 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 715 | return __get_pair<1>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 719 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 720 | constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT |
| 721 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 722 | return __get_pair<1>::get(_VSTD::move(__p)); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 725 | template <class _T1, class _T2> |
| 726 | inline _LIBCPP_INLINE_VISIBILITY |
| 727 | constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT |
| 728 | { |
| 729 | return __get_pair<1>::get(_VSTD::move(__p)); |
| 730 | } |
| 731 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 732 | #endif |
| 733 | |
| 734 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 735 | |
| 736 | template<class _Tp, _Tp... _Ip> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 737 | struct _LIBCPP_TYPE_VIS_ONLY integer_sequence |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 738 | { |
| 739 | typedef _Tp value_type; |
| 740 | static_assert( is_integral<_Tp>::value, |
| 741 | "std::integer_sequence can only be instantiated with an integral type" ); |
| 742 | static |
| 743 | _LIBCPP_INLINE_VISIBILITY |
| 744 | constexpr |
| 745 | size_t |
| 746 | size() noexcept { return sizeof...(_Ip); } |
| 747 | }; |
| 748 | |
| 749 | template<size_t... _Ip> |
| 750 | using index_sequence = integer_sequence<size_t, _Ip...>; |
| 751 | |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 752 | #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) |
| 753 | |
| 754 | template <class _Tp, _Tp _Ep> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 755 | using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>; |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 756 | |
| 757 | #else |
| 758 | |
Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 759 | template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 760 | typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 761 | |
| 762 | template <class _Tp, _Tp _Ep> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 763 | struct __make_integer_sequence_checked |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 764 | { |
| 765 | static_assert(is_integral<_Tp>::value, |
| 766 | "std::make_integer_sequence can only be instantiated with an integral type" ); |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 767 | static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length"); |
Eric Fiselier | d6a12b3 | 2015-12-16 00:35:45 +0000 | [diff] [blame] | 768 | // Workaround GCC bug by preventing bad installations when 0 <= _Ep |
| 769 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 |
| 770 | typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 771 | }; |
| 772 | |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 773 | template <class _Tp, _Tp _Ep> |
| 774 | using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type; |
| 775 | |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 776 | #endif |
| 777 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 778 | template<class _Tp, _Tp _Np> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 779 | using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 780 | |
| 781 | template<size_t _Np> |
| 782 | using make_index_sequence = make_integer_sequence<size_t, _Np>; |
| 783 | |
| 784 | template<class... _Tp> |
| 785 | using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; |
Marshall Clow | 5270a84 | 2016-06-19 19:29:52 +0000 | [diff] [blame] | 786 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 787 | #endif // _LIBCPP_STD_VER > 11 |
| 788 | |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 789 | #if _LIBCPP_STD_VER > 11 |
| 790 | template<class _T1, class _T2 = _T1> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 791 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 792 | _T1 exchange(_T1& __obj, _T2 && __new_value) |
| 793 | { |
Howard Hinnant | 171771a | 2013-07-08 21:06:38 +0000 | [diff] [blame] | 794 | _T1 __old_value = _VSTD::move(__obj); |
| 795 | __obj = _VSTD::forward<_T2>(__new_value); |
| 796 | return __old_value; |
Marshall Clow | 5270a84 | 2016-06-19 19:29:52 +0000 | [diff] [blame] | 797 | } |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 798 | #endif // _LIBCPP_STD_VER > 11 |
| 799 | |
Eric Fiselier | eef85d9 | 2016-07-23 22:19:19 +0000 | [diff] [blame^] | 800 | #if _LIBCPP_STD_VER > 14 |
| 801 | |
| 802 | struct _LIBCPP_TYPE_VIS_ONLY __in_place_tag {}; |
| 803 | template <class> struct _LIBCPP_TYPE_VIS_ONLY __in_place_type_tag {}; |
| 804 | template <size_t> struct _LIBCPP_TYPE_VIS_ONLY __in_place_index_tag {}; |
| 805 | |
| 806 | struct _LIBCPP_TYPE_VIS_ONLY in_place_tag; |
| 807 | |
| 808 | using in_place_t = in_place_tag(&)(__in_place_tag); |
| 809 | template <class _Tp> |
| 810 | using in_place_type_t = in_place_tag(&)(__in_place_type_tag<_Tp>); |
| 811 | template <size_t _Nx> |
| 812 | using in_place_index_t = in_place_tag(&)(__in_place_index_tag<_Nx>); |
| 813 | |
| 814 | struct in_place_tag { |
| 815 | in_place_tag() = delete; |
| 816 | private: |
| 817 | explicit in_place_tag(__in_place_tag) {} |
| 818 | |
| 819 | friend inline in_place_tag in_place(__in_place_tag __t); |
| 820 | template <class _Tp> |
| 821 | friend inline in_place_tag in_place(__in_place_type_tag<_Tp>); |
| 822 | template <size_t _Nx> |
| 823 | friend inline in_place_tag in_place(__in_place_index_tag<_Nx>); |
| 824 | }; |
| 825 | |
| 826 | inline in_place_tag in_place(__in_place_tag __t) { |
| 827 | _LIBCPP_ASSERT(false, "The in_place function cannot be invoked"); |
| 828 | return in_place_tag(__t); |
| 829 | } |
| 830 | template <class _Tp> |
| 831 | inline in_place_tag in_place(__in_place_type_tag<_Tp>) { |
| 832 | _LIBCPP_ASSERT(false, "The in_place function cannot be invoked"); |
| 833 | return in_place_tag(__in_place_tag{}); |
| 834 | } |
| 835 | template <size_t _Nx> |
| 836 | inline in_place_tag in_place(__in_place_index_tag<_Nx>) { |
| 837 | _LIBCPP_ASSERT(false, "The in_place function cannot be invoked"); |
| 838 | return in_place_tag(__in_place_tag{}); |
| 839 | } |
| 840 | |
| 841 | #endif // _LIBCPP_STD_VER > 14 |
| 842 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 843 | _LIBCPP_END_NAMESPACE_STD |
| 844 | |
| 845 | #endif // _LIBCPP_UTILITY |