get_non_const.pass.cpp revision 8fc4f5a2510e709331c6fcc3ba401a36f98128fc
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#if __cplusplus > 201103L
22struct S {
23   std::pair<int, int> a;
24   int k;
25   constexpr S() : a{1,2}, k(std::get<0>(a)) {}
26   };
27
28constexpr std::pair<int, int> getP () { return { 3, 4 }; }
29#endif
30
31int main()
32{
33    {
34        typedef std::pair<int, short> P;
35        P p(3, 4);
36        assert(std::get<0>(p) == 3);
37        assert(std::get<1>(p) == 4);
38        std::get<0>(p) = 5;
39        std::get<1>(p) = 6;
40        assert(std::get<0>(p) == 5);
41        assert(std::get<1>(p) == 6);
42    }
43
44#if __cplusplus > 201103L
45    {
46        static_assert(S().k == 1, "");
47        static_assert(std::get<1>(getP()) == 4, "");
48    }
49#endif
50
51}
52