| 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 | // <utility> |
| 10 | |
| 11 | // template <class T1, class T2> struct pair |
| 12 | |
| 13 | // template<size_t I, class T1, class T2> |
| 14 | // typename tuple_element<I, std::pair<T1, T2> >::type& |
| 15 | // get(pair<T1, T2>&); |
| 16 | |
| 17 | #include <utility> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | |
| 22 | #if TEST_STD_VER > 11 |
| 23 | struct S { |
| 24 | std::pair<int, int> a; |
| 25 | int k; |
| 26 | constexpr S() : a{1,2}, k(std::get<0>(a)) {} |
| 27 | }; |
| 28 | |
| 29 | constexpr std::pair<int, int> getP () { return { 3, 4 }; } |
| 30 | #endif |
| 31 | |
| 32 | int main(int, char**) |
| 33 | { |
| 34 | { |
| 35 | typedef std::pair<int, short> P; |
| 36 | P p(3, static_cast<short>(4)); |
| 37 | assert(std::get<0>(p) == 3); |
| 38 | assert(std::get<1>(p) == 4); |
| 39 | std::get<0>(in&: p) = 5; |
| 40 | std::get<1>(in&: p) = 6; |
| 41 | assert(std::get<0>(p) == 5); |
| 42 | assert(std::get<1>(p) == 6); |
| 43 | } |
| 44 | |
| 45 | #if TEST_STD_VER > 11 |
| 46 | { |
| 47 | static_assert(S().k == 1, "" ); |
| 48 | static_assert(std::get<1>(getP()) == 4, "" ); |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |