1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef _LIBCPP___UTILITY_PAIR_H
10 #define _LIBCPP___UTILITY_PAIR_H
11
12 #include <__config>
13 #include <__functional/unwrap_ref.h>
14 #include <__tuple>
15 #include <__utility/forward.h>
16 #include <__utility/move.h>
17 #include <__utility/piecewise_construct.h>
18 #include <cstddef>
19 #include <type_traits>
20
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 #pragma GCC system_header
23 #endif
24
25 _LIBCPP_PUSH_MACROS
26 #include <__undef_macros>
27
28 _LIBCPP_BEGIN_NAMESPACE_STD
29
30
31 #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
32 template <class, class>
33 struct __non_trivially_copyable_base {
34 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
__non_trivially_copyable_base__non_trivially_copyable_base35 __non_trivially_copyable_base() _NOEXCEPT {}
36 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__non_trivially_copyable_base__non_trivially_copyable_base37 __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}
38 };
39 #endif
40
41 template <class _T1, class _T2>
42 struct _LIBCPP_TEMPLATE_VIS pair
43 #if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
44 : private __non_trivially_copyable_base<_T1, _T2>
45 #endif
46 {
47 typedef _T1 first_type;
48 typedef _T2 second_type;
49
50 _T1 first;
51 _T2 second;
52
53 #if !defined(_LIBCPP_CXX03_LANG)
54 pair(pair const&) = default;
55 pair(pair&&) = default;
56 #else
57 // Use the implicitly declared copy constructor in C++03
58 #endif
59
60 #ifdef _LIBCPP_CXX03_LANG
61 _LIBCPP_INLINE_VISIBILITY
pairpair62 pair() : first(), second() {}
63
64 _LIBCPP_INLINE_VISIBILITY
pairpair65 pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}
66
67 template <class _U1, class _U2>
68 _LIBCPP_INLINE_VISIBILITY
pairpair69 pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
70
71 _LIBCPP_INLINE_VISIBILITY
72 pair& operator=(pair const& __p) {
73 first = __p.first;
74 second = __p.second;
75 return *this;
76 }
77 #else
78 template <bool _Val>
79 using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type;
80
81 struct _CheckArgs {
82 template <int&...>
__enable_explicit_defaultpair::_CheckArgs83 static constexpr bool __enable_explicit_default() {
84 return is_default_constructible<_T1>::value
85 && is_default_constructible<_T2>::value
86 && !__enable_implicit_default<>();
87 }
88
89 template <int&...>
__enable_implicit_defaultpair::_CheckArgs90 static constexpr bool __enable_implicit_default() {
91 return __is_implicitly_default_constructible<_T1>::value
92 && __is_implicitly_default_constructible<_T2>::value;
93 }
94
95 template <class _U1, class _U2>
__enable_explicitpair::_CheckArgs96 static constexpr bool __enable_explicit() {
97 return is_constructible<first_type, _U1>::value
98 && is_constructible<second_type, _U2>::value
99 && (!is_convertible<_U1, first_type>::value
100 || !is_convertible<_U2, second_type>::value);
101 }
102
103 template <class _U1, class _U2>
__enable_implicitpair::_CheckArgs104 static constexpr bool __enable_implicit() {
105 return is_constructible<first_type, _U1>::value
106 && is_constructible<second_type, _U2>::value
107 && is_convertible<_U1, first_type>::value
108 && is_convertible<_U2, second_type>::value;
109 }
110 };
111
112 template <bool _MaybeEnable>
113 using _CheckArgsDep _LIBCPP_NODEBUG_TYPE = typename conditional<
114 _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
115
116 struct _CheckTupleLikeConstructor {
117 template <class _Tuple>
__enable_implicitpair::_CheckTupleLikeConstructor118 static constexpr bool __enable_implicit() {
119 return __tuple_convertible<_Tuple, pair>::value;
120 }
121
122 template <class _Tuple>
__enable_explicitpair::_CheckTupleLikeConstructor123 static constexpr bool __enable_explicit() {
124 return __tuple_constructible<_Tuple, pair>::value
125 && !__tuple_convertible<_Tuple, pair>::value;
126 }
127
128 template <class _Tuple>
__enable_assignpair::_CheckTupleLikeConstructor129 static constexpr bool __enable_assign() {
130 return __tuple_assignable<_Tuple, pair>::value;
131 }
132 };
133
134 template <class _Tuple>
135 using _CheckTLC _LIBCPP_NODEBUG_TYPE = typename conditional<
136 __tuple_like_with_size<_Tuple, 2>::value
137 && !is_same<typename decay<_Tuple>::type, pair>::value,
138 _CheckTupleLikeConstructor,
139 __check_tuple_constructor_fail
140 >::type;
141
142 template<bool _Dummy = true, _EnableB<
143 _CheckArgsDep<_Dummy>::__enable_explicit_default()
144 > = false>
145 explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
pairpair146 pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
147 is_nothrow_default_constructible<second_type>::value)
148 : first(), second() {}
149
150 template<bool _Dummy = true, _EnableB<
151 _CheckArgsDep<_Dummy>::__enable_implicit_default()
152 > = false>
153 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
pairpair154 pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
155 is_nothrow_default_constructible<second_type>::value)
156 : first(), second() {}
157
158 template <bool _Dummy = true, _EnableB<
159 _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
160 > = false>
161 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair162 explicit pair(_T1 const& __t1, _T2 const& __t2)
163 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
164 is_nothrow_copy_constructible<second_type>::value)
165 : first(__t1), second(__t2) {}
166
167 template<bool _Dummy = true, _EnableB<
168 _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
169 > = false>
170 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair171 pair(_T1 const& __t1, _T2 const& __t2)
172 _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
173 is_nothrow_copy_constructible<second_type>::value)
174 : first(__t1), second(__t2) {}
175
176 template<class _U1, class _U2, _EnableB<
177 _CheckArgs::template __enable_explicit<_U1, _U2>()
178 > = false>
179 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair180 explicit pair(_U1&& __u1, _U2&& __u2)
181 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
182 is_nothrow_constructible<second_type, _U2>::value))
183 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
184
185 template<class _U1, class _U2, _EnableB<
186 _CheckArgs::template __enable_implicit<_U1, _U2>()
187 > = false>
188 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair189 pair(_U1&& __u1, _U2&& __u2)
190 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
191 is_nothrow_constructible<second_type, _U2>::value))
192 : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
193
194 template<class _U1, class _U2, _EnableB<
195 _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
196 > = false>
197 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair198 explicit pair(pair<_U1, _U2> const& __p)
199 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
200 is_nothrow_constructible<second_type, _U2 const&>::value))
201 : first(__p.first), second(__p.second) {}
202
203 template<class _U1, class _U2, _EnableB<
204 _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
205 > = false>
206 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair207 pair(pair<_U1, _U2> const& __p)
208 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
209 is_nothrow_constructible<second_type, _U2 const&>::value))
210 : first(__p.first), second(__p.second) {}
211
212 template<class _U1, class _U2, _EnableB<
213 _CheckArgs::template __enable_explicit<_U1, _U2>()
214 > = false>
215 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair216 explicit pair(pair<_U1, _U2>&&__p)
217 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
218 is_nothrow_constructible<second_type, _U2&&>::value))
219 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
220
221 template<class _U1, class _U2, _EnableB<
222 _CheckArgs::template __enable_implicit<_U1, _U2>()
223 > = false>
224 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair225 pair(pair<_U1, _U2>&& __p)
226 _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
227 is_nothrow_constructible<second_type, _U2&&>::value))
228 : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
229
230 template<class _Tuple, _EnableB<
231 _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
232 > = false>
233 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair234 explicit pair(_Tuple&& __p)
235 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
236 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
237
238 template<class _Tuple, _EnableB<
239 _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
240 > = false>
241 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pairpair242 pair(_Tuple&& __p)
243 : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
244 second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
245
246 template <class... _Args1, class... _Args2>
247 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pairpair248 pair(piecewise_construct_t __pc,
249 tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
250 _NOEXCEPT_((is_nothrow_constructible<first_type, _Args1...>::value &&
251 is_nothrow_constructible<second_type, _Args2...>::value))
252 : pair(__pc, __first_args, __second_args,
253 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
254 typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
255
256 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
257 pair& operator=(typename conditional<
258 is_copy_assignable<first_type>::value &&
259 is_copy_assignable<second_type>::value,
260 pair, __nat>::type const& __p)
_NOEXCEPT_pair261 _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
262 is_nothrow_copy_assignable<second_type>::value)
263 {
264 first = __p.first;
265 second = __p.second;
266 return *this;
267 }
268
269 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
270 pair& operator=(typename conditional<
271 is_move_assignable<first_type>::value &&
272 is_move_assignable<second_type>::value,
273 pair, __nat>::type&& __p)
_NOEXCEPT_pair274 _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
275 is_nothrow_move_assignable<second_type>::value)
276 {
277 first = _VSTD::forward<first_type>(__p.first);
278 second = _VSTD::forward<second_type>(__p.second);
279 return *this;
280 }
281
282 template <class _Tuple, _EnableB<
283 _CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
284 > = false>
285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
286 pair& operator=(_Tuple&& __p) {
287 first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
288 second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p));
289 return *this;
290 }
291 #endif
292
293 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
294 void
swappair295 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
296 __is_nothrow_swappable<second_type>::value)
297 {
298 using _VSTD::swap;
299 swap(first, __p.first);
300 swap(second, __p.second);
301 }
302 private:
303
304 #ifndef _LIBCPP_CXX03_LANG
305 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
306 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
307 pair(piecewise_construct_t,
308 tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
309 __tuple_indices<_I1...>, __tuple_indices<_I2...>);
310 #endif
311 };
312
313 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
314 template<class _T1, class _T2>
315 pair(_T1, _T2) -> pair<_T1, _T2>;
316 #endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
317
318 template <class _T1, class _T2>
319 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
320 bool
321 operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
322 {
323 return __x.first == __y.first && __x.second == __y.second;
324 }
325
326 template <class _T1, class _T2>
327 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
328 bool
329 operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
330 {
331 return !(__x == __y);
332 }
333
334 template <class _T1, class _T2>
335 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
336 bool
337 operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
338 {
339 return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
340 }
341
342 template <class _T1, class _T2>
343 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
344 bool
345 operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
346 {
347 return __y < __x;
348 }
349
350 template <class _T1, class _T2>
351 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
352 bool
353 operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
354 {
355 return !(__x < __y);
356 }
357
358 template <class _T1, class _T2>
359 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
360 bool
361 operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
362 {
363 return !(__y < __x);
364 }
365
366 template <class _T1, class _T2>
367 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
368 typename enable_if
369 <
370 __is_swappable<_T1>::value &&
371 __is_swappable<_T2>::value,
372 void
373 >::type
swap(pair<_T1,_T2> & __x,pair<_T1,_T2> & __y)374 swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
375 _NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
376 __is_nothrow_swappable<_T2>::value))
377 {
378 __x.swap(__y);
379 }
380
381 #ifndef _LIBCPP_CXX03_LANG
382
383 template <class _T1, class _T2>
384 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
385 pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
make_pair(_T1 && __t1,_T2 && __t2)386 make_pair(_T1&& __t1, _T2&& __t2)
387 {
388 return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
389 (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
390 }
391
392 #else // _LIBCPP_CXX03_LANG
393
394 template <class _T1, class _T2>
395 inline _LIBCPP_INLINE_VISIBILITY
396 pair<_T1,_T2>
make_pair(_T1 __x,_T2 __y)397 make_pair(_T1 __x, _T2 __y)
398 {
399 return pair<_T1, _T2>(__x, __y);
400 }
401
402 #endif // _LIBCPP_CXX03_LANG
403
404 template <class _T1, class _T2>
405 struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
406 : public integral_constant<size_t, 2> {};
407
408 template <size_t _Ip, class _T1, class _T2>
409 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
410 {
411 static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
412 };
413
414 template <class _T1, class _T2>
415 struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
416 {
417 typedef _LIBCPP_NODEBUG_TYPE _T1 type;
418 };
419
420 template <class _T1, class _T2>
421 struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> >
422 {
423 typedef _LIBCPP_NODEBUG_TYPE _T2 type;
424 };
425
426 template <size_t _Ip> struct __get_pair;
427
428 template <>
429 struct __get_pair<0>
430 {
431 template <class _T1, class _T2>
432 static
433 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
434 _T1&
435 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
436
437 template <class _T1, class _T2>
438 static
439 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
440 const _T1&
441 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
442
443 #ifndef _LIBCPP_CXX03_LANG
444 template <class _T1, class _T2>
445 static
446 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
447 _T1&&
448 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
449
450 template <class _T1, class _T2>
451 static
452 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
453 const _T1&&
454 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
455 #endif // _LIBCPP_CXX03_LANG
456 };
457
458 template <>
459 struct __get_pair<1>
460 {
461 template <class _T1, class _T2>
462 static
463 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
464 _T2&
465 get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
466
467 template <class _T1, class _T2>
468 static
469 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
470 const _T2&
471 get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
472
473 #ifndef _LIBCPP_CXX03_LANG
474 template <class _T1, class _T2>
475 static
476 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
477 _T2&&
478 get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
479
480 template <class _T1, class _T2>
481 static
482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
483 const _T2&&
484 get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
485 #endif // _LIBCPP_CXX03_LANG
486 };
487
488 template <size_t _Ip, class _T1, class _T2>
489 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
490 typename tuple_element<_Ip, pair<_T1, _T2> >::type&
491 get(pair<_T1, _T2>& __p) _NOEXCEPT
492 {
493 return __get_pair<_Ip>::get(__p);
494 }
495
496 template <size_t _Ip, class _T1, class _T2>
497 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
498 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
499 get(const pair<_T1, _T2>& __p) _NOEXCEPT
500 {
501 return __get_pair<_Ip>::get(__p);
502 }
503
504 #ifndef _LIBCPP_CXX03_LANG
505 template <size_t _Ip, class _T1, class _T2>
506 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
507 typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
508 get(pair<_T1, _T2>&& __p) _NOEXCEPT
509 {
510 return __get_pair<_Ip>::get(_VSTD::move(__p));
511 }
512
513 template <size_t _Ip, class _T1, class _T2>
514 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
515 const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
516 get(const pair<_T1, _T2>&& __p) _NOEXCEPT
517 {
518 return __get_pair<_Ip>::get(_VSTD::move(__p));
519 }
520 #endif // _LIBCPP_CXX03_LANG
521
522 #if _LIBCPP_STD_VER > 11
523 template <class _T1, class _T2>
524 inline _LIBCPP_INLINE_VISIBILITY
525 constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
526 {
527 return __get_pair<0>::get(__p);
528 }
529
530 template <class _T1, class _T2>
531 inline _LIBCPP_INLINE_VISIBILITY
532 constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
533 {
534 return __get_pair<0>::get(__p);
535 }
536
537 template <class _T1, class _T2>
538 inline _LIBCPP_INLINE_VISIBILITY
539 constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
540 {
541 return __get_pair<0>::get(_VSTD::move(__p));
542 }
543
544 template <class _T1, class _T2>
545 inline _LIBCPP_INLINE_VISIBILITY
546 constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
547 {
548 return __get_pair<0>::get(_VSTD::move(__p));
549 }
550
551 template <class _T1, class _T2>
552 inline _LIBCPP_INLINE_VISIBILITY
553 constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
554 {
555 return __get_pair<1>::get(__p);
556 }
557
558 template <class _T1, class _T2>
559 inline _LIBCPP_INLINE_VISIBILITY
560 constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
561 {
562 return __get_pair<1>::get(__p);
563 }
564
565 template <class _T1, class _T2>
566 inline _LIBCPP_INLINE_VISIBILITY
567 constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
568 {
569 return __get_pair<1>::get(_VSTD::move(__p));
570 }
571
572 template <class _T1, class _T2>
573 inline _LIBCPP_INLINE_VISIBILITY
574 constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
575 {
576 return __get_pair<1>::get(_VSTD::move(__p));
577 }
578
579 #endif
580
581 _LIBCPP_END_NAMESPACE_STD
582
583 _LIBCPP_POP_MACROS
584
585 #endif // _LIBCPP___UTILITY_PAIR_H
586