]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/utility/pairs/pair.astuple/get_non_const.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / utility / pairs / pair.astuple / get_non_const.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <utility>
11
12 // template <class T1, class T2> struct pair
13
14 // template<size_t I, class T1, class T2>
15 //     typename tuple_element<I, std::pair<T1, T2> >::type&
16 //     get(pair<T1, T2>&);
17
18 #include <utility>
19 #include <cassert>
20
21 #include "test_macros.h"
22
23 #if TEST_STD_VER > 11
24 struct S {
25    std::pair<int, int> a;
26    int k;
27    constexpr S() : a{1,2}, k(std::get<0>(a)) {}
28    };
29
30 constexpr std::pair<int, int> getP () { return { 3, 4 }; }
31 #endif
32
33 int main()
34 {
35     {
36         typedef std::pair<int, short> P;
37         P p(3, static_cast<short>(4));
38         assert(std::get<0>(p) == 3);
39         assert(std::get<1>(p) == 4);
40         std::get<0>(p) = 5;
41         std::get<1>(p) = 6;
42         assert(std::get<0>(p) == 5);
43         assert(std::get<1>(p) == 6);
44     }
45
46 #if TEST_STD_VER > 11
47     {
48         static_assert(S().k == 1, "");
49         static_assert(std::get<1>(getP()) == 4, "");
50     }
51 #endif
52
53 }