| 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 |  | 
 | 41 | template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; | 
 | 42 | template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; | 
 | 43 |  | 
 | 44 | template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; | 
| 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 | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 53 |     move_if_noexcept(T& x) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 |  | 
 | 55 | template <class T> typename add_rvalue_reference<T>::type declval() noexcept; | 
 | 56 |  | 
 | 57 | template <class T1, class T2> | 
 | 58 | struct pair | 
 | 59 | { | 
 | 60 |     typedef T1 first_type; | 
 | 61 |     typedef T2 second_type; | 
 | 62 |  | 
 | 63 |     T1 first; | 
 | 64 |     T2 second; | 
 | 65 |  | 
 | 66 |     pair(const pair&) = default; | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 67 |     pair(pair&&) = default; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 |     constexpr pair(); | 
 | 69 |     pair(const T1& x, const T2& y); | 
 | 70 |     template <class U, class V> pair(U&& x, V&& y); | 
 | 71 |     template <class U, class V> pair(const pair<U, V>& p); | 
 | 72 |     template <class U, class V> pair(pair<U, V>&& p); | 
 | 73 |     template <class... Args1, class... Args2> | 
 | 74 |         pair(piecewise_construct_t, tuple<Args1...> first_args, | 
 | 75 |              tuple<Args2...> second_args); | 
 | 76 |  | 
 | 77 |     template <class U, class V> pair& operator=(const pair<U, V>& p); | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 78 |     pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && | 
 | 79 |                                        is_nothrow_move_assignable<T2>::value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 |     template <class U, class V> pair& operator=(pair<U, V>&& p); | 
 | 81 |  | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 82 |     void swap(pair& p) noexcept(noexcept(swap(first, p.first)) && | 
 | 83 |                                 noexcept(swap(second, p.second))); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | }; | 
 | 85 |  | 
 | 86 | template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); | 
 | 87 | template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); | 
 | 88 | template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); | 
 | 89 | template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); | 
 | 90 | template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); | 
 | 91 | template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); | 
 | 92 |  | 
 | 93 | template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 94 | template <class T1, class T2> | 
 | 95 | void | 
 | 96 | 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] | 97 |  | 
 | 98 | struct piecewise_construct_t { }; | 
 | 99 | constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); | 
 | 100 |  | 
 | 101 | template <class T> class tuple_size; | 
 | 102 | template <size_t I, class T> class tuple_element; | 
 | 103 |  | 
 | 104 | template <class T1, class T2> struct tuple_size<std::pair<T1, T2> >; | 
 | 105 | template <class T1, class T2> struct tuple_element<0, std::pair<T1, T2> >; | 
 | 106 | template <class T1, class T2> struct tuple_element<1, std::pair<T1, T2> >; | 
 | 107 |  | 
 | 108 | template<size_t I, class T1, class T2> | 
 | 109 |     typename tuple_element<I, std::pair<T1, T2> >::type& | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 110 |     get(std::pair<T1, T2>&) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 |  | 
 | 112 | template<size_t I, class T1, class T2> | 
 | 113 |     const typename const tuple_element<I, std::pair<T1, T2> >::type& | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 114 |     get(const std::pair<T1, T2>&) noexcept; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 |  | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 116 | template<size_t I, class T1, class T2> | 
 | 117 |     typename tuple_element<I, std::pair<T1, T2> >::type&& | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 118 |     get(std::pair<T1, T2>&&) noexcept; | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 119 |  | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 120 | // C++14 | 
 | 121 |  | 
 | 122 | template<class T, T... I> | 
 | 123 | struct integer_sequence | 
 | 124 | { | 
 | 125 |     typedef T value_type; | 
 | 126 |  | 
 | 127 |     static constexpr size_t size() noexcept; | 
 | 128 | }; | 
 | 129 |  | 
 | 130 | template<size_t... I> | 
 | 131 |   using index_sequence = integer_sequence<size_t, I...>; | 
 | 132 |  | 
 | 133 | template<class T, T N> | 
 | 134 |   using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; | 
 | 135 | template<size_t N> | 
 | 136 |   using make_index_sequence = make_integer_sequence<size_t, N>; | 
 | 137 |  | 
 | 138 | template<class... T> | 
 | 139 |   using index_sequence_for = make_index_sequence<sizeof...(T)>; | 
 | 140 |  | 
| Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 141 | template<class T, class U=T>  | 
 | 142 |     T exchange(T& obj, U&& new_value); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 143 | }  // std | 
 | 144 |  | 
 | 145 | */ | 
 | 146 |  | 
 | 147 | #include <__config> | 
 | 148 | #include <__tuple> | 
 | 149 | #include <type_traits> | 
 | 150 |  | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 151 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 152 | #pragma GCC system_header | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 153 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 154 |  | 
 | 155 | _LIBCPP_BEGIN_NAMESPACE_STD | 
 | 156 |  | 
 | 157 | namespace rel_ops | 
 | 158 | { | 
 | 159 |  | 
 | 160 | template<class _Tp> | 
 | 161 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 162 | bool | 
 | 163 | operator!=(const _Tp& __x, const _Tp& __y) | 
 | 164 | { | 
 | 165 |     return !(__x == __y); | 
 | 166 | } | 
 | 167 |  | 
 | 168 | template<class _Tp> | 
 | 169 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 170 | bool | 
 | 171 | operator> (const _Tp& __x, const _Tp& __y) | 
 | 172 | { | 
 | 173 |     return __y < __x; | 
 | 174 | } | 
 | 175 |  | 
 | 176 | template<class _Tp> | 
 | 177 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 178 | bool | 
 | 179 | operator<=(const _Tp& __x, const _Tp& __y) | 
 | 180 | { | 
 | 181 |     return !(__y < __x); | 
 | 182 | } | 
 | 183 |  | 
 | 184 | template<class _Tp> | 
 | 185 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 186 | bool | 
 | 187 | operator>=(const _Tp& __x, const _Tp& __y) | 
 | 188 | { | 
 | 189 |     return !(__x < __y); | 
 | 190 | } | 
 | 191 |  | 
 | 192 | }  // rel_ops | 
 | 193 |  | 
 | 194 | // swap_ranges | 
 | 195 |  | 
 | 196 | template <class _ForwardIterator1, class _ForwardIterator2> | 
 | 197 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 198 | _ForwardIterator2 | 
 | 199 | swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) | 
 | 200 | { | 
 | 201 |     for(; __first1 != __last1; ++__first1, ++__first2) | 
 | 202 |         swap(*__first1, *__first2); | 
 | 203 |     return __first2; | 
 | 204 | } | 
 | 205 |  | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 206 | template<class _Tp, size_t _Np> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 207 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 208 | void | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 209 | 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] | 210 | { | 
| Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 211 |     _VSTD::swap_ranges(__a, __a + _Np, __b); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 212 | } | 
 | 213 |  | 
 | 214 | template <class _Tp> | 
 | 215 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 216 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 217 | typename conditional | 
 | 218 | < | 
| Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 219 |     !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 |     const _Tp&, | 
 | 221 |     _Tp&& | 
 | 222 | >::type | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 223 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | const _Tp& | 
 | 225 | #endif | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 226 | move_if_noexcept(_Tp& __x) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 227 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 228 |     return _VSTD::move(__x); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 229 | } | 
 | 230 |  | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 231 | struct _LIBCPP_TYPE_VIS piecewise_construct_t { }; | 
| Howard Hinnant | 616e92d | 2012-04-03 23:45:46 +0000 | [diff] [blame] | 232 | #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_UTILITY) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 233 | extern const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); | 
| Howard Hinnant | 2a5349b | 2012-04-03 21:09:48 +0000 | [diff] [blame] | 234 | #else | 
 | 235 | constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); | 
 | 236 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 237 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 238 | template <class _T1, class _T2> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 239 | struct _LIBCPP_TYPE_VIS pair | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 240 | { | 
 | 241 |     typedef _T1 first_type; | 
 | 242 |     typedef _T2 second_type; | 
 | 243 |  | 
 | 244 |     _T1 first; | 
 | 245 |     _T2 second; | 
 | 246 |  | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 247 |     // pair(const pair&) = default; | 
 | 248 |     // pair(pair&&) = default; | 
 | 249 |  | 
| Howard Hinnant | 2a5349b | 2012-04-03 21:09:48 +0000 | [diff] [blame] | 250 |     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR pair() : first(), second() {} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 |  | 
 | 252 |     _LIBCPP_INLINE_VISIBILITY pair(const _T1& __x, const _T2& __y) | 
 | 253 |         : first(__x), second(__y) {} | 
 | 254 |  | 
| Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 255 |     template<class _U1, class _U2> | 
 | 256 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 9c59d38 | 2011-07-27 19:25:28 +0000 | [diff] [blame] | 257 |         pair(const pair<_U1, _U2>& __p | 
 | 258 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE | 
| Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 259 |                  ,typename enable_if<is_convertible<const _U1&, _T1>::value && | 
 | 260 |                                     is_convertible<const _U2&, _T2>::value>::type* = 0 | 
| Howard Hinnant | 9c59d38 | 2011-07-27 19:25:28 +0000 | [diff] [blame] | 261 | #endif | 
 | 262 |                                       ) | 
| Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 263 |             : first(__p.first), second(__p.second) {} | 
 | 264 |  | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 265 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 266 |     pair(const pair& __p) | 
 | 267 |         _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && | 
 | 268 |                    is_nothrow_copy_constructible<second_type>::value) | 
 | 269 |         : first(__p.first), | 
 | 270 |           second(__p.second) | 
 | 271 |     { | 
 | 272 |     } | 
 | 273 |  | 
 | 274 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 275 |     pair& operator=(const pair& __p) | 
| Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 276 |         _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && | 
 | 277 |                    is_nothrow_copy_assignable<second_type>::value) | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 278 |     { | 
 | 279 |         first = __p.first; | 
 | 280 |         second = __p.second; | 
 | 281 |         return *this; | 
 | 282 |     } | 
 | 283 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 284 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 |  | 
 | 286 |     template <class _U1, class _U2, | 
| Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 287 |               class = typename enable_if<is_convertible<_U1, first_type>::value && | 
 | 288 |                                          is_convertible<_U2, second_type>::value>::type> | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 289 |         _LIBCPP_INLINE_VISIBILITY | 
 | 290 |         pair(_U1&& __u1, _U2&& __u2) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 291 |             : first(_VSTD::forward<_U1>(__u1)), | 
 | 292 |               second(_VSTD::forward<_U2>(__u2)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 293 |             {} | 
 | 294 |  | 
| Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 295 |     template<class _U1, class _U2> | 
 | 296 |         _LIBCPP_INLINE_VISIBILITY | 
 | 297 |         pair(pair<_U1, _U2>&& __p, | 
| Howard Hinnant | fe59276 | 2012-06-09 20:01:23 +0000 | [diff] [blame] | 298 |                  typename enable_if<is_convertible<_U1, _T1>::value && | 
 | 299 |                                     is_convertible<_U2, _T2>::value>::type* = 0) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 300 |             : first(_VSTD::forward<_U1>(__p.first)), | 
 | 301 |               second(_VSTD::forward<_U2>(__p.second)) {} | 
| Howard Hinnant | 469d419 | 2011-04-29 18:10:55 +0000 | [diff] [blame] | 302 |  | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 303 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 61aa601 | 2011-07-01 19:24:36 +0000 | [diff] [blame] | 304 |     pair(pair&& __p) _NOEXCEPT_(is_nothrow_move_constructible<first_type>::value && | 
 | 305 |                                 is_nothrow_move_constructible<second_type>::value) | 
 | 306 |         : first(_VSTD::forward<first_type>(__p.first)), | 
 | 307 |           second(_VSTD::forward<second_type>(__p.second)) | 
 | 308 |     { | 
 | 309 |     } | 
 | 310 |  | 
 | 311 |     _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 312 |     pair& | 
 | 313 |     operator=(pair&& __p) _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && | 
 | 314 |                                      is_nothrow_move_assignable<second_type>::value) | 
 | 315 |     { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 316 |         first = _VSTD::forward<first_type>(__p.first); | 
 | 317 |         second = _VSTD::forward<second_type>(__p.second); | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 318 |         return *this; | 
 | 319 |     } | 
 | 320 |  | 
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 321 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
 | 322 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 323 |     template<class _Tuple, | 
 | 324 |              class = typename enable_if<__tuple_convertible<_Tuple, pair>::value>::type> | 
 | 325 |         _LIBCPP_INLINE_VISIBILITY | 
 | 326 |         pair(_Tuple&& __p) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 327 |             : first(_VSTD::forward<typename tuple_element<0, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 328 |                                   typename __make_tuple_types<_Tuple>::type>::type>(get<0>(__p))), | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 329 |               second(_VSTD::forward<typename tuple_element<1, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 330 |                                    typename __make_tuple_types<_Tuple>::type>::type>(get<1>(__p))) | 
 | 331 |             {} | 
 | 332 |  | 
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 333 |  | 
| Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 334 |  | 
| Howard Hinnant | 6cc99fa | 2011-12-19 17:58:44 +0000 | [diff] [blame] | 335 |     template <class... _Args1, class... _Args2> | 
| Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 336 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 337 |         pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args, | 
 | 338 |                                     tuple<_Args2...> __second_args) | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 339 |             : pair(__pc, __first_args, __second_args, | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 340 |                    typename __make_tuple_indices<sizeof...(_Args1)>::type(), | 
 | 341 |                    typename __make_tuple_indices<sizeof...(_Args2) >::type()) | 
 | 342 |             {} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 343 |  | 
 | 344 |     template <class _Tuple, | 
 | 345 |               class = typename enable_if<__tuple_assignable<_Tuple, pair>::value>::type> | 
| Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 346 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 |         pair& | 
 | 348 |         operator=(_Tuple&& __p) | 
 | 349 |         { | 
 | 350 |             typedef typename __make_tuple_types<_Tuple>::type _TupleRef; | 
 | 351 |             typedef typename tuple_element<0, _TupleRef>::type _U0; | 
 | 352 |             typedef typename tuple_element<1, _TupleRef>::type _U1; | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 353 |             first  = _VSTD::forward<_U0>(_VSTD::get<0>(__p)); | 
 | 354 |             second = _VSTD::forward<_U1>(_VSTD::get<1>(__p)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 |             return *this; | 
 | 356 |         } | 
 | 357 |  | 
| Michael J. Spencer | 626916f | 2010-12-10 19:47:54 +0000 | [diff] [blame] | 358 | #endif  // _LIBCPP_HAS_NO_VARIADICS | 
 | 359 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 360 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 361 |     _LIBCPP_INLINE_VISIBILITY | 
 | 362 |     void | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 363 |     swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && | 
 | 364 |                                __is_nothrow_swappable<second_type>::value) | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 365 |     { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 366 |         _VSTD::iter_swap(&first, &__p.first); | 
 | 367 |         _VSTD::iter_swap(&second, &__p.second); | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 368 |     } | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | private: | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 370 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | #ifndef _LIBCPP_HAS_NO_VARIADICS | 
 | 372 |     template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> | 
| Howard Hinnant | 5f5859c | 2011-01-13 20:05:05 +0000 | [diff] [blame] | 373 |         _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 |         pair(piecewise_construct_t, | 
 | 375 |              tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, | 
 | 376 |              __tuple_indices<_I1...>, __tuple_indices<_I2...>); | 
| Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 377 | #endif  // _LIBCPP_HAS_NO_VARIADICS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 378 | }; | 
 | 379 |  | 
 | 380 | template <class _T1, class _T2> | 
 | 381 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 382 | bool | 
 | 383 | operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) | 
 | 384 | { | 
 | 385 |     return __x.first == __y.first && __x.second == __y.second; | 
 | 386 | } | 
 | 387 |  | 
 | 388 | template <class _T1, class _T2> | 
 | 389 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 390 | bool | 
 | 391 | operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) | 
 | 392 | { | 
 | 393 |     return !(__x == __y); | 
 | 394 | } | 
 | 395 |  | 
 | 396 | template <class _T1, class _T2> | 
 | 397 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 398 | bool | 
 | 399 | operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) | 
 | 400 | { | 
 | 401 |     return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); | 
 | 402 | } | 
 | 403 |  | 
 | 404 | template <class _T1, class _T2> | 
 | 405 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 406 | bool | 
 | 407 | operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) | 
 | 408 | { | 
 | 409 |     return __y < __x; | 
 | 410 | } | 
 | 411 |  | 
 | 412 | template <class _T1, class _T2> | 
 | 413 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 414 | bool | 
 | 415 | operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) | 
 | 416 | { | 
 | 417 |     return !(__x < __y); | 
 | 418 | } | 
 | 419 |  | 
 | 420 | template <class _T1, class _T2> | 
 | 421 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 422 | bool | 
 | 423 | operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) | 
 | 424 | { | 
 | 425 |     return !(__y < __x); | 
 | 426 | } | 
 | 427 |  | 
 | 428 | template <class _T1, class _T2> | 
 | 429 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | aabf287 | 2011-06-01 19:59:32 +0000 | [diff] [blame] | 430 | typename enable_if | 
 | 431 | < | 
 | 432 |     __is_swappable<_T1>::value && | 
 | 433 |     __is_swappable<_T2>::value, | 
 | 434 |     void | 
 | 435 | >::type | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 437 |                      _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && | 
 | 438 |                                  __is_nothrow_swappable<_T2>::value)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | { | 
| Howard Hinnant | e9b2c2d | 2011-05-27 15:04:19 +0000 | [diff] [blame] | 440 |     __x.swap(__y); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | } | 
 | 442 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 443 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 |  | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 445 | template <class _Tp> class _LIBCPP_TYPE_VIS reference_wrapper; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 446 |  | 
 | 447 | template <class _Tp> | 
 | 448 | struct ___make_pair_return | 
 | 449 | { | 
 | 450 |     typedef _Tp type; | 
 | 451 | }; | 
 | 452 |  | 
 | 453 | template <class _Tp> | 
 | 454 | struct ___make_pair_return<reference_wrapper<_Tp>> | 
 | 455 | { | 
 | 456 |     typedef _Tp& type; | 
 | 457 | }; | 
 | 458 |  | 
 | 459 | template <class _Tp> | 
 | 460 | struct __make_pair_return | 
 | 461 | { | 
 | 462 |     typedef typename ___make_pair_return<typename decay<_Tp>::type>::type type; | 
 | 463 | }; | 
 | 464 |  | 
 | 465 | template <class _T1, class _T2> | 
| Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 466 | inline _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | pair<typename __make_pair_return<_T1>::type, typename __make_pair_return<_T2>::type> | 
 | 468 | make_pair(_T1&& __t1, _T2&& __t2) | 
 | 469 | { | 
 | 470 |     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] | 471 |                (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | } | 
 | 473 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 474 | #else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 |  | 
 | 476 | template <class _T1, class _T2> | 
 | 477 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 478 | pair<_T1,_T2> | 
 | 479 | make_pair(_T1 __x, _T2 __y) | 
 | 480 | { | 
 | 481 |     return pair<_T1, _T2>(__x, __y); | 
 | 482 | } | 
 | 483 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 484 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 486 | template <class _T1, class _T2> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 487 |   class _LIBCPP_TYPE_VIS tuple_size<pair<_T1, _T2> > | 
| Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 488 |     : public integral_constant<size_t, 2> {}; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 |  | 
 | 490 | template <class _T1, class _T2> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 491 |   class _LIBCPP_TYPE_VIS tuple_size<const pair<_T1, _T2> > | 
| Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 492 |     : public integral_constant<size_t, 2> {}; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 493 |  | 
 | 494 | template <class _T1, class _T2> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 495 | class _LIBCPP_TYPE_VIS tuple_element<0, pair<_T1, _T2> > | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 496 | { | 
 | 497 | public: | 
 | 498 |     typedef _T1 type; | 
 | 499 | }; | 
 | 500 |  | 
 | 501 | template <class _T1, class _T2> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 502 | class _LIBCPP_TYPE_VIS tuple_element<1, pair<_T1, _T2> > | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | { | 
 | 504 | public: | 
 | 505 |     typedef _T2 type; | 
 | 506 | }; | 
 | 507 |  | 
 | 508 | template <class _T1, class _T2> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 509 | class _LIBCPP_TYPE_VIS tuple_element<0, const pair<_T1, _T2> > | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | { | 
 | 511 | public: | 
 | 512 |     typedef const _T1 type; | 
 | 513 | }; | 
 | 514 |  | 
 | 515 | template <class _T1, class _T2> | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 516 | class _LIBCPP_TYPE_VIS tuple_element<1, const pair<_T1, _T2> > | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | { | 
 | 518 | public: | 
 | 519 |     typedef const _T2 type; | 
 | 520 | }; | 
 | 521 |  | 
 | 522 | template <size_t _Ip> struct __get_pair; | 
 | 523 |  | 
 | 524 | template <> | 
 | 525 | struct __get_pair<0> | 
 | 526 | { | 
 | 527 |     template <class _T1, class _T2> | 
 | 528 |     static | 
 | 529 |     _LIBCPP_INLINE_VISIBILITY | 
 | 530 |     _T1& | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 531 |     get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 |  | 
 | 533 |     template <class _T1, class _T2> | 
 | 534 |     static | 
 | 535 |     _LIBCPP_INLINE_VISIBILITY | 
 | 536 |     const _T1& | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 537 |     get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 538 |  | 
 | 539 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 540 |  | 
 | 541 |     template <class _T1, class _T2> | 
 | 542 |     static | 
 | 543 |     _LIBCPP_INLINE_VISIBILITY | 
 | 544 |     _T1&& | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 545 |     get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 546 |  | 
 | 547 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 | }; | 
 | 549 |  | 
 | 550 | template <> | 
 | 551 | struct __get_pair<1> | 
 | 552 | { | 
 | 553 |     template <class _T1, class _T2> | 
 | 554 |     static | 
 | 555 |     _LIBCPP_INLINE_VISIBILITY | 
 | 556 |     _T2& | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 557 |     get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 |  | 
 | 559 |     template <class _T1, class _T2> | 
 | 560 |     static | 
 | 561 |     _LIBCPP_INLINE_VISIBILITY | 
 | 562 |     const _T2& | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 563 |     get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 564 |  | 
 | 565 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 566 |  | 
 | 567 |     template <class _T1, class _T2> | 
 | 568 |     static | 
 | 569 |     _LIBCPP_INLINE_VISIBILITY | 
 | 570 |     _T2&& | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 571 |     get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 572 |  | 
 | 573 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | }; | 
 | 575 |  | 
 | 576 | template <size_t _Ip, class _T1, class _T2> | 
 | 577 | _LIBCPP_INLINE_VISIBILITY inline | 
 | 578 | typename tuple_element<_Ip, pair<_T1, _T2> >::type& | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 579 | get(pair<_T1, _T2>& __p) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | { | 
 | 581 |     return __get_pair<_Ip>::get(__p); | 
 | 582 | } | 
 | 583 |  | 
 | 584 | template <size_t _Ip, class _T1, class _T2> | 
 | 585 | _LIBCPP_INLINE_VISIBILITY inline | 
 | 586 | const typename tuple_element<_Ip, pair<_T1, _T2> >::type& | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 587 | get(const pair<_T1, _T2>& __p) _NOEXCEPT | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 588 | { | 
 | 589 |     return __get_pair<_Ip>::get(__p); | 
 | 590 | } | 
 | 591 |  | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 592 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 593 |  | 
 | 594 | template <size_t _Ip, class _T1, class _T2> | 
 | 595 | _LIBCPP_INLINE_VISIBILITY inline | 
 | 596 | typename tuple_element<_Ip, pair<_T1, _T2> >::type&& | 
| Howard Hinnant | a5e0121 | 2011-05-27 19:08:18 +0000 | [diff] [blame] | 597 | get(pair<_T1, _T2>&& __p) _NOEXCEPT | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 598 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 599 |     return __get_pair<_Ip>::get(_VSTD::move(__p)); | 
| Howard Hinnant | cd2254b | 2010-11-17 19:52:17 +0000 | [diff] [blame] | 600 | } | 
 | 601 |  | 
 | 602 | #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
 | 603 |  | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 604 | #if _LIBCPP_STD_VER > 11 | 
 | 605 |  | 
 | 606 | template<class _Tp, _Tp... _Ip> | 
| Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 607 | struct _LIBCPP_TYPE_VIS integer_sequence | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 608 | { | 
 | 609 |     typedef _Tp value_type; | 
 | 610 |     static_assert( is_integral<_Tp>::value, | 
 | 611 |                   "std::integer_sequence can only be instantiated with an integral type" ); | 
 | 612 |     static | 
 | 613 |     _LIBCPP_INLINE_VISIBILITY | 
 | 614 |     constexpr | 
 | 615 |     size_t | 
 | 616 |     size() noexcept { return sizeof...(_Ip); } | 
 | 617 | }; | 
 | 618 |  | 
 | 619 | template<size_t... _Ip> | 
 | 620 |     using index_sequence = integer_sequence<size_t, _Ip...>; | 
 | 621 |  | 
| Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 622 | namespace __detail { | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 623 |  | 
| Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 624 | template<typename _Tp, size_t ..._Extra> struct __repeat; | 
 | 625 | template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> { | 
 | 626 |   typedef integer_sequence<_Tp, | 
 | 627 |                            _Np..., | 
 | 628 |                            sizeof...(_Np) + _Np..., | 
 | 629 |                            2 * sizeof...(_Np) + _Np..., | 
 | 630 |                            3 * sizeof...(_Np) + _Np..., | 
 | 631 |                            4 * sizeof...(_Np) + _Np..., | 
 | 632 |                            5 * sizeof...(_Np) + _Np..., | 
 | 633 |                            6 * sizeof...(_Np) + _Np..., | 
 | 634 |                            7 * sizeof...(_Np) + _Np..., | 
 | 635 |                            _Extra...> type; | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 636 | }; | 
 | 637 |  | 
| Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 638 | template<size_t _Np> struct __parity; | 
 | 639 | template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {}; | 
 | 640 |  | 
 | 641 | template<> struct __make<0> { typedef integer_sequence<size_t> type; }; | 
 | 642 | template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; }; | 
 | 643 | template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; }; | 
 | 644 | template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; }; | 
 | 645 | template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; }; | 
 | 646 | template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; }; | 
 | 647 | template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; }; | 
 | 648 | template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; }; | 
 | 649 |  | 
 | 650 | template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; }; | 
 | 651 | template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; }; | 
 | 652 | template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; }; | 
 | 653 | template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; }; | 
 | 654 | template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; | 
 | 655 | template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; | 
 | 656 | template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; | 
 | 657 | template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; }; | 
 | 658 |  | 
 | 659 | template<typename _Tp, typename _Up> struct __convert { | 
 | 660 |   template<typename> struct __result; | 
 | 661 |   template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; }; | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 662 | }; | 
| Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 663 | template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; }; | 
 | 664 |  | 
 | 665 | } | 
 | 666 |  | 
 | 667 | template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = | 
 | 668 |   typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type; | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 669 |  | 
 | 670 | template <class _Tp, _Tp _Ep> | 
 | 671 | struct __make_integer_sequence | 
 | 672 | { | 
 | 673 |     static_assert(is_integral<_Tp>::value, | 
 | 674 |                   "std::make_integer_sequence can only be instantiated with an integral type" ); | 
 | 675 |     static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative"); | 
| Marshall Clow | 42e55e9 | 2013-07-03 19:20:30 +0000 | [diff] [blame] | 676 |     typedef __make_integer_sequence_unchecked<_Tp, _Ep> type; | 
| Marshall Clow | 7ec46bc | 2013-07-01 16:26:55 +0000 | [diff] [blame] | 677 | }; | 
 | 678 |  | 
 | 679 | template<class _Tp, _Tp _Np> | 
 | 680 |     using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type; | 
 | 681 |  | 
 | 682 | template<size_t _Np> | 
 | 683 |     using make_index_sequence = make_integer_sequence<size_t, _Np>; | 
 | 684 |  | 
 | 685 | template<class... _Tp> | 
 | 686 |     using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; | 
 | 687 |    | 
 | 688 | #endif  // _LIBCPP_STD_VER > 11 | 
 | 689 |  | 
| Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 690 | #if _LIBCPP_STD_VER > 11 | 
 | 691 | template<class _T1, class _T2 = _T1> | 
 | 692 | _LIBCPP_INLINE_VISIBILITY inline | 
 | 693 | _T1 exchange(_T1& __obj, _T2 && __new_value) | 
 | 694 | { | 
| Howard Hinnant | 171771a | 2013-07-08 21:06:38 +0000 | [diff] [blame^] | 695 |     _T1 __old_value = _VSTD::move(__obj); | 
 | 696 |     __obj = _VSTD::forward<_T2>(__new_value); | 
 | 697 |     return __old_value; | 
 | 698 | }     | 
| Marshall Clow | e2735d1 | 2013-07-08 20:54:40 +0000 | [diff] [blame] | 699 | #endif  // _LIBCPP_STD_VER > 11 | 
 | 700 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 701 | _LIBCPP_END_NAMESPACE_STD | 
 | 702 |  | 
 | 703 | #endif  // _LIBCPP_UTILITY |