• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <tuple>
11 
12 // template <class... Types> class tuple;
13 
14 // template <size_t I, class... Types>
15 //   typename tuple_element<I, tuple<Types...> >::type&
16 //   get(tuple<Types...>& t);
17 
18 // UNSUPPORTED: c++98, c++03
19 
20 #include <tuple>
21 #include <string>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 
26 #if TEST_STD_VER > 11
27 
28 struct Empty {};
29 
30 struct S {
31    std::tuple<int, Empty> a;
32    int k;
33    Empty e;
SS34    constexpr S() : a{1,Empty{}}, k(std::get<0>(a)), e(std::get<1>(a)) {}
35    };
36 
getP()37 constexpr std::tuple<int, int> getP () { return { 3, 4 }; }
38 #endif
39 
main()40 int main()
41 {
42     {
43         typedef std::tuple<int> T;
44         T t(3);
45         assert(std::get<0>(t) == 3);
46         std::get<0>(t) = 2;
47         assert(std::get<0>(t) == 2);
48     }
49     {
50         typedef std::tuple<std::string, int> T;
51         T t("high", 5);
52         assert(std::get<0>(t) == "high");
53         assert(std::get<1>(t) == 5);
54         std::get<0>(t) = "four";
55         std::get<1>(t) = 4;
56         assert(std::get<0>(t) == "four");
57         assert(std::get<1>(t) == 4);
58     }
59     {
60         typedef std::tuple<double&, std::string, int> T;
61         double d = 1.5;
62         T t(d, "high", 5);
63         assert(std::get<0>(t) == 1.5);
64         assert(std::get<1>(t) == "high");
65         assert(std::get<2>(t) == 5);
66         std::get<0>(t) = 2.5;
67         std::get<1>(t) = "four";
68         std::get<2>(t) = 4;
69         assert(std::get<0>(t) == 2.5);
70         assert(std::get<1>(t) == "four");
71         assert(std::get<2>(t) == 4);
72         assert(d == 2.5);
73     }
74 #if TEST_STD_VER > 11
75     { // get on an rvalue tuple
76         static_assert ( std::get<0> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 0, "" );
77         static_assert ( std::get<1> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 1, "" );
78         static_assert ( std::get<2> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 2, "" );
79         static_assert ( std::get<3> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 3, "" );
80         static_assert(S().k == 1, "");
81         static_assert(std::get<1>(getP()) == 4, "");
82     }
83 #endif
84 
85 }
86