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); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 174 | } // std |
| 175 | |
| 176 | */ |
| 177 | |
| 178 | #include <__config> |
| 179 | #include <__tuple> |
| 180 | #include <type_traits> |
Ben Craig | d59d416 | 2016-04-19 20:13:55 +0000 | [diff] [blame] | 181 | #include <initializer_list> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 182 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 183 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 185 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | |
| 187 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 188 | |
| 189 | namespace rel_ops |
| 190 | { |
| 191 | |
| 192 | template<class _Tp> |
| 193 | inline _LIBCPP_INLINE_VISIBILITY |
| 194 | bool |
| 195 | operator!=(const _Tp& __x, const _Tp& __y) |
| 196 | { |
| 197 | return !(__x == __y); |
| 198 | } |
| 199 | |
| 200 | template<class _Tp> |
| 201 | inline _LIBCPP_INLINE_VISIBILITY |
| 202 | bool |
| 203 | operator> (const _Tp& __x, const _Tp& __y) |
| 204 | { |
| 205 | return __y < __x; |
| 206 | } |
| 207 | |
| 208 | template<class _Tp> |
| 209 | inline _LIBCPP_INLINE_VISIBILITY |
| 210 | bool |
| 211 | operator<=(const _Tp& __x, const _Tp& __y) |
| 212 | { |
| 213 | return !(__y < __x); |
| 214 | } |
| 215 | |
| 216 | template<class _Tp> |
| 217 | inline _LIBCPP_INLINE_VISIBILITY |
| 218 | bool |
| 219 | operator>=(const _Tp& __x, const _Tp& __y) |
| 220 | { |
| 221 | return !(__x < __y); |
| 222 | } |
| 223 | |
| 224 | } // rel_ops |
| 225 | |
| 226 | // swap_ranges |
| 227 | |
Marshall Clow | fd8ed7f | 2015-01-06 19:20:49 +0000 | [diff] [blame] | 228 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 229 | template <class _ForwardIterator1, class _ForwardIterator2> |
| 230 | inline _LIBCPP_INLINE_VISIBILITY |
| 231 | _ForwardIterator2 |
| 232 | swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) |
| 233 | { |
Eric Fiselier | b991975 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 234 | for(; __first1 != __last1; ++__first1, (void) ++__first2) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | swap(*__first1, *__first2); |
| 236 | return __first2; |
| 237 | } |
| 238 | |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 239 | // forward declared in <type_traits> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 240 | template<class _Tp, size_t _Np> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 8f1e73d | 2016-04-21 23:38:59 +0000 | [diff] [blame] | 242 | typename enable_if< |
| 243 | __is_swappable<_Tp>::value |
| 244 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 245 | 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] | 246 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 247 | _VSTD::swap_ranges(__a, __a + _Np, __b); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | template <class _Tp> |
Marshall Clow | 01a0e90 | 2013-07-15 20:46:11 +0000 | [diff] [blame] | 251 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 252 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 253 | typename conditional |
| 254 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 255 | !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 256 | const _Tp&, |
| 257 | _Tp&& |
| 258 | >::type |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 259 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 260 | const _Tp& |
| 261 | #endif |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 262 | move_if_noexcept(_Tp& __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 264 | return _VSTD::move(__x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Marshall Clow | f60d092 | 2015-11-17 00:08:08 +0000 | [diff] [blame] | 267 | #if _LIBCPP_STD_VER > 14 |
| 268 | template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } |
| 269 | template <class _Tp> void as_const(const _Tp&&) = delete; |
| 270 | #endif |
| 271 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 272 | struct _LIBCPP_TYPE_VIS_ONLY piecewise_construct_t { }; |
Howard Hinnant | 616e92d | 2012-04-03 23:45:46 +0000 | [diff] [blame] | 273 | #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); |
Howard Hinnant | 2a5349b | 2012-04-03 21:09:48 +0000 | [diff] [blame] | 275 | #else |
| 276 | constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); |
| 277 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 279 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 280 | struct _LIBCPP_TYPE_VIS_ONLY pair |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 281 | { |
| 282 | typedef _T1 first_type; |
| 283 | typedef _T2 second_type; |
| 284 | |
| 285 | _T1 first; |
| 286 | _T2 second; |
| 287 | |
Eric Fiselier | 9bef1ff | 2015-12-23 08:20:26 +0000 | [diff] [blame] | 288 | #ifndef _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS |
| 289 | template <bool _Dummy = true, class = typename enable_if< |
| 290 | __dependent_type<is_default_constructible<_T1>, _Dummy>::value && |
| 291 | __dependent_type<is_default_constructible<_T2>, _Dummy>::value |
| 292 | >::type> |
| 293 | #endif |
Howard Hinnant | 2a5349b | 2012-04-03 21:09:48 +0000 | [diff] [blame] | 294 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 295 | |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 296 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 297 | pair(const _T1& __x, const _T2& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 298 | : first(__x), second(__y) {} |
| 299 | |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 300 | template<class _U1, class _U2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 301 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 9c59d38 | 2011-07-27 19:25:28 +0000 | [diff] [blame] | 302 | pair(const pair<_U1, _U2>& __p |
| 303 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 304 | ,typename enable_if<is_convertible<const _U1&, _T1>::value && |
| 305 | is_convertible<const _U2&, _T2>::value>::type* = 0 |
Howard Hinnant | 9c59d38 | 2011-07-27 19:25:28 +0000 | [diff] [blame] | 306 | #endif |
| 307 | ) |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 308 | : first(__p.first), second(__p.second) {} |
| 309 | |
Eric Fiselier | c71c304 | 2016-07-18 01:58:37 +0000 | [diff] [blame^] | 310 | #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) |
Eric Fiselier | d9e1819 | 2016-06-14 14:34:19 +0000 | [diff] [blame] | 311 | _LIBCPP_INLINE_VISIBILITY |
| 312 | pair(const pair& __p) |
| 313 | _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && |
| 314 | is_nothrow_copy_constructible<second_type>::value) |
| 315 | : first(__p.first), |
| 316 | second(__p.second) |
| 317 | { |
| 318 | } |
Eric Fiselier | c71c304 | 2016-07-18 01:58:37 +0000 | [diff] [blame^] | 319 | |
| 320 | # ifndef _LIBCPP_CXX03_LANG |
| 321 | _LIBCPP_INLINE_VISIBILITY |
| 322 | pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value && |
| 323 | is_nothrow_move_constructible<second_type>::value) |
| 324 | : first(_VSTD::forward<first_type>(__p.first)), |
| 325 | second(_VSTD::forward<second_type>(__p.second)) |
| 326 | { |
| 327 | } |
| 328 | # endif |
| 329 | #elif !defined(_LIBCPP_CXX03_LANG) |
| 330 | pair(pair const&) = default; |
| 331 | pair(pair&&) = default; |
| 332 | #else |
| 333 | // Use the implicitly declared copy constructor in C++03 |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 334 | #endif |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 335 | |
| 336 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 337 | pair& operator=(const pair& __p) |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 338 | _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && |
| 339 | is_nothrow_copy_assignable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 340 | { |
| 341 | first = __p.first; |
| 342 | second = __p.second; |
| 343 | return *this; |
| 344 | } |
| 345 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 346 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | |
| 348 | template <class _U1, class _U2, |
Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 349 | class = typename enable_if<is_convertible<_U1, first_type>::value && |
| 350 | is_convertible<_U2, second_type>::value>::type> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 351 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | pair(_U1&& __u1, _U2&& __u2) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 353 | : first(_VSTD::forward<_U1>(__u1)), |
| 354 | second(_VSTD::forward<_U2>(__u2)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | {} |
| 356 | |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 357 | template<class _U1, class _U2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 358 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 359 | pair(pair<_U1, _U2>&& __p, |
Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 360 | typename enable_if<is_convertible<_U1, _T1>::value && |
| 361 | is_convertible<_U2, _T2>::value>::type* = 0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 362 | : first(_VSTD::forward<_U1>(__p.first)), |
| 363 | second(_VSTD::forward<_U2>(__p.second)) {} |
Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 364 | |
Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 365 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 366 | pair& |
| 367 | operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && |
| 368 | is_nothrow_move_assignable<second_type>::value) |
| 369 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 370 | first = _VSTD::forward<first_type>(__p.first); |
| 371 | second = _VSTD::forward<second_type>(__p.second); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 372 | return *this; |
| 373 | } |
| 374 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 375 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 376 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | template<class _Tuple, |
| 378 | class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 379 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 380 | pair(_Tuple&& __p) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 381 | : first(_VSTD::forward<typename tuple_element<0, |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 382 | typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<0>(__p))), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 383 | second(_VSTD::forward<typename tuple_element<1, |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 384 | typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<1>(__p))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | {} |
| 386 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 387 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 388 | |
Howard Hinnant | 6cc99fa | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 389 | template <class... _Args1, class... _Args2> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 390 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, |
| 392 | tuple<_Args2...> __second_args) |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 393 | : pair(__pc, __first_args, __second_args, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | typename __make_tuple_indices<sizeof...(_Args1)>::type(), |
| 395 | typename __make_tuple_indices<sizeof...(_Args2) >::type()) |
| 396 | {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | |
| 398 | template <class _Tuple, |
| 399 | class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | pair& |
| 402 | operator=(_Tuple&& __p) |
| 403 | { |
| 404 | typedef typename __make_tuple_types<_Tuple>::type _TupleRef; |
| 405 | typedef typename tuple_element<0, _TupleRef>::type _U0; |
| 406 | typedef typename tuple_element<1, _TupleRef>::type _U1; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 407 | first = _VSTD::forward<_U0>(_VSTD::get<0>(__p)); |
| 408 | second = _VSTD::forward<_U1>(_VSTD::get<1>(__p)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | return *this; |
| 410 | } |
| 411 | |
Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 412 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 413 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 414 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 415 | _LIBCPP_INLINE_VISIBILITY |
| 416 | void |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 417 | swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && |
| 418 | __is_nothrow_swappable<second_type>::value) |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 419 | { |
Marshall Clow | 6b0e419 | 2015-09-22 17:50:11 +0000 | [diff] [blame] | 420 | using _VSTD::swap; |
| 421 | swap(first, __p.first); |
| 422 | swap(second, __p.second); |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 423 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | private: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 425 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 426 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 427 | template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> |
Howard Hinnant | 5f5859c | 2011-01-13 20:05:05 +0000 | [diff] [blame] | 428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | pair(piecewise_construct_t, |
| 430 | tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, |
| 431 | __tuple_indices<_I1...>, __tuple_indices<_I2...>); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 432 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 436 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 437 | bool |
| 438 | operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 439 | { |
| 440 | return __x.first == __y.first && __x.second == __y.second; |
| 441 | } |
| 442 | |
| 443 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 444 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | bool |
| 446 | operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 447 | { |
| 448 | return !(__x == __y); |
| 449 | } |
| 450 | |
| 451 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 452 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 453 | bool |
| 454 | operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 455 | { |
| 456 | return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); |
| 457 | } |
| 458 | |
| 459 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 460 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 461 | bool |
| 462 | operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 463 | { |
| 464 | return __y < __x; |
| 465 | } |
| 466 | |
| 467 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 468 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | bool |
| 470 | operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 471 | { |
| 472 | return !(__x < __y); |
| 473 | } |
| 474 | |
| 475 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 476 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 477 | bool |
| 478 | operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) |
| 479 | { |
| 480 | return !(__y < __x); |
| 481 | } |
| 482 | |
| 483 | template <class _T1, class _T2> |
| 484 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 485 | typename enable_if |
| 486 | < |
| 487 | __is_swappable<_T1>::value && |
| 488 | __is_swappable<_T2>::value, |
| 489 | void |
| 490 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 491 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 492 | _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && |
| 493 | __is_nothrow_swappable<_T2>::value)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | { |
Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 495 | __x.swap(__y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 498 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 499 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | |
| 501 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 502 | struct __make_pair_return_impl |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | { |
| 504 | typedef _Tp type; |
| 505 | }; |
| 506 | |
| 507 | template <class _Tp> |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 508 | struct __make_pair_return_impl<reference_wrapper<_Tp>> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 509 | { |
| 510 | typedef _Tp& type; |
| 511 | }; |
| 512 | |
| 513 | template <class _Tp> |
| 514 | struct __make_pair_return |
| 515 | { |
Marshall Clow | a71f956 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 516 | typedef typename __make_pair_return_impl<typename decay<_Tp>::type>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | template <class _T1, class _T2> |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 520 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 521 | pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> |
| 522 | make_pair(_T1&& __t1, _T2&& __t2) |
| 523 | { |
| 524 | 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] | 525 | (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 528 | #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 529 | |
| 530 | template <class _T1, class _T2> |
| 531 | inline _LIBCPP_INLINE_VISIBILITY |
| 532 | pair<_T1,_T2> |
| 533 | make_pair(_T1 __x, _T2 __y) |
| 534 | { |
| 535 | return pair<_T1, _T2>(__x, __y); |
| 536 | } |
| 537 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 538 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 540 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 541 | class _LIBCPP_TYPE_VIS_ONLY tuple_size<pair<_T1, _T2> > |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 542 | : public integral_constant<size_t, 2> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 543 | |
| 544 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 545 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<0, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | { |
| 547 | public: |
| 548 | typedef _T1 type; |
| 549 | }; |
| 550 | |
| 551 | template <class _T1, class _T2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 552 | class _LIBCPP_TYPE_VIS_ONLY tuple_element<1, pair<_T1, _T2> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 553 | { |
| 554 | public: |
| 555 | typedef _T2 type; |
| 556 | }; |
| 557 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | template <size_t _Ip> struct __get_pair; |
| 559 | |
| 560 | template <> |
| 561 | struct __get_pair<0> |
| 562 | { |
| 563 | template <class _T1, class _T2> |
| 564 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 565 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 567 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 568 | |
| 569 | template <class _T1, class _T2> |
| 570 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 571 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 572 | const _T1& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 573 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 574 | |
| 575 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 576 | |
| 577 | template <class _T1, class _T2> |
| 578 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 579 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 580 | _T1&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 581 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 582 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 583 | template <class _T1, class _T2> |
| 584 | static |
| 585 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 586 | const _T1&& |
| 587 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);} |
| 588 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 589 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 590 | }; |
| 591 | |
| 592 | template <> |
| 593 | struct __get_pair<1> |
| 594 | { |
| 595 | template <class _T1, class _T2> |
| 596 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 597 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 598 | _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 599 | get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | |
| 601 | template <class _T1, class _T2> |
| 602 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 603 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | const _T2& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 605 | get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 606 | |
| 607 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 608 | |
| 609 | template <class _T1, class _T2> |
| 610 | static |
Marshall Clow | 8fc4f5a | 2013-07-17 18:25:36 +0000 | [diff] [blame] | 611 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 612 | _T2&& |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 613 | get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 614 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 615 | template <class _T1, class _T2> |
| 616 | static |
| 617 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 618 | const _T2&& |
| 619 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);} |
| 620 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 621 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | }; |
| 623 | |
| 624 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 625 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 627 | get(pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 628 | { |
| 629 | return __get_pair<_Ip>::get(__p); |
| 630 | } |
| 631 | |
| 632 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 633 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 635 | get(const pair<_T1, _T2>& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 636 | { |
| 637 | return __get_pair<_Ip>::get(__p); |
| 638 | } |
| 639 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 640 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 641 | |
| 642 | template <size_t _Ip, class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 643 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 644 | typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 645 | get(pair<_T1, _T2>&& __p) _NOEXCEPT |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 646 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 647 | return __get_pair<_Ip>::get(_VSTD::move(__p)); |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 650 | template <size_t _Ip, class _T1, class _T2> |
| 651 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 652 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& |
| 653 | get(const pair<_T1, _T2>&& __p) _NOEXCEPT |
| 654 | { |
| 655 | return __get_pair<_Ip>::get(_VSTD::move(__p)); |
| 656 | } |
| 657 | |
Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 658 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 659 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 660 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 661 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 662 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 663 | constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT |
| 664 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 665 | return __get_pair<0>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 669 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 670 | constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT |
| 671 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 672 | return __get_pair<0>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 676 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 677 | constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT |
| 678 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 679 | return __get_pair<0>::get(_VSTD::move(__p)); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 683 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 684 | constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT |
| 685 | { |
| 686 | return __get_pair<0>::get(_VSTD::move(__p)); |
| 687 | } |
| 688 | |
| 689 | template <class _T1, class _T2> |
| 690 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 691 | constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT |
| 692 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 693 | return __get_pair<1>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 697 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 698 | constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT |
| 699 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 700 | return __get_pair<1>::get(__p); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | template <class _T1, class _T2> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 704 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 705 | constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT |
| 706 | { |
Marshall Clow | 206f6cd | 2013-07-16 17:45:44 +0000 | [diff] [blame] | 707 | return __get_pair<1>::get(_VSTD::move(__p)); |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Eric Fiselier | 199bee0 | 2015-12-18 00:36:55 +0000 | [diff] [blame] | 710 | template <class _T1, class _T2> |
| 711 | inline _LIBCPP_INLINE_VISIBILITY |
| 712 | constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT |
| 713 | { |
| 714 | return __get_pair<1>::get(_VSTD::move(__p)); |
| 715 | } |
| 716 | |
Marshall Clow | e8029e5 | 2013-07-13 02:54:05 +0000 | [diff] [blame] | 717 | #endif |
| 718 | |
| 719 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 720 | |
| 721 | template<class _Tp, _Tp... _Ip> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 722 | struct _LIBCPP_TYPE_VIS_ONLY integer_sequence |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 723 | { |
| 724 | typedef _Tp value_type; |
| 725 | static_assert( is_integral<_Tp>::value, |
| 726 | "std::integer_sequence can only be instantiated with an integral type" ); |
| 727 | static |
| 728 | _LIBCPP_INLINE_VISIBILITY |
| 729 | constexpr |
| 730 | size_t |
| 731 | size() noexcept { return sizeof...(_Ip); } |
| 732 | }; |
| 733 | |
| 734 | template<size_t... _Ip> |
| 735 | using index_sequence = integer_sequence<size_t, _Ip...>; |
| 736 | |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 737 | #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) |
| 738 | |
| 739 | template <class _Tp, _Tp _Ep> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 740 | using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>; |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 741 | |
| 742 | #else |
| 743 | |
Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 744 | template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 745 | typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 746 | |
| 747 | template <class _Tp, _Tp _Ep> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 748 | struct __make_integer_sequence_checked |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 749 | { |
| 750 | static_assert(is_integral<_Tp>::value, |
| 751 | "std::make_integer_sequence can only be instantiated with an integral type" ); |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 752 | 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] | 753 | // Workaround GCC bug by preventing bad installations when 0 <= _Ep |
| 754 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 |
| 755 | typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 756 | }; |
| 757 | |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 758 | template <class _Tp, _Tp _Ep> |
| 759 | using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type; |
| 760 | |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 761 | #endif |
| 762 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 763 | template<class _Tp, _Tp _Np> |
Eric Fiselier | a3ccd96 | 2016-06-30 22:34:43 +0000 | [diff] [blame] | 764 | using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 765 | |
| 766 | template<size_t _Np> |
| 767 | using make_index_sequence = make_integer_sequence<size_t, _Np>; |
| 768 | |
| 769 | template<class... _Tp> |
| 770 | using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; |
Marshall Clow | 5270a84 | 2016-06-19 19:29:52 +0000 | [diff] [blame] | 771 | |
Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 772 | #endif // _LIBCPP_STD_VER > 11 |
| 773 | |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 774 | #if _LIBCPP_STD_VER > 11 |
| 775 | template<class _T1, class _T2 = _T1> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 776 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 777 | _T1 exchange(_T1& __obj, _T2 && __new_value) |
| 778 | { |
Howard Hinnant | 171771a | 2013-07-08 21:06:38 +0000 | [diff] [blame] | 779 | _T1 __old_value = _VSTD::move(__obj); |
| 780 | __obj = _VSTD::forward<_T2>(__new_value); |
| 781 | return __old_value; |
Marshall Clow | 5270a84 | 2016-06-19 19:29:52 +0000 | [diff] [blame] | 782 | } |
Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 783 | #endif // _LIBCPP_STD_VER > 11 |
| 784 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 785 | _LIBCPP_END_NAMESPACE_STD |
| 786 | |
| 787 | #endif // _LIBCPP_UTILITY |