• 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 <class... UTypes> tuple(tuple<UTypes...>&& u);
15 
16 // UNSUPPORTED: c++98, c++03
17 
18 #include <tuple>
19 #include <string>
20 #include <memory>
21 #include <cassert>
22 
23 struct Explicit {
24   int value;
ExplicitExplicit25   explicit Explicit(int x) : value(x) {}
26 };
27 
28 struct Implicit {
29   int value;
ImplicitImplicit30   Implicit(int x) : value(x) {}
31 };
32 
33 struct B
34 {
35     int id_;
36 
BB37     explicit B(int i) : id_(i) {}
38 
~BB39     virtual ~B() {}
40 };
41 
42 struct D
43     : B
44 {
DD45     explicit D(int i) : B(i) {}
46 };
47 
main()48 int main()
49 {
50     {
51         typedef std::tuple<long> T0;
52         typedef std::tuple<long long> T1;
53         T0 t0(2);
54         T1 t1 = std::move(t0);
55         assert(std::get<0>(t1) == 2);
56     }
57     {
58         typedef std::tuple<long, char> T0;
59         typedef std::tuple<long long, int> T1;
60         T0 t0(2, 'a');
61         T1 t1 = std::move(t0);
62         assert(std::get<0>(t1) == 2);
63         assert(std::get<1>(t1) == int('a'));
64     }
65     {
66         typedef std::tuple<long, char, D> T0;
67         typedef std::tuple<long long, int, B> T1;
68         T0 t0(2, 'a', D(3));
69         T1 t1 = std::move(t0);
70         assert(std::get<0>(t1) == 2);
71         assert(std::get<1>(t1) == int('a'));
72         assert(std::get<2>(t1).id_ == 3);
73     }
74     {
75         D d(3);
76         typedef std::tuple<long, char, D&> T0;
77         typedef std::tuple<long long, int, B&> T1;
78         T0 t0(2, 'a', d);
79         T1 t1 = std::move(t0);
80         d.id_ = 2;
81         assert(std::get<0>(t1) == 2);
82         assert(std::get<1>(t1) == int('a'));
83         assert(std::get<2>(t1).id_ == 2);
84     }
85     {
86         typedef std::tuple<long, char, std::unique_ptr<D>> T0;
87         typedef std::tuple<long long, int, std::unique_ptr<B>> T1;
88         T0 t0(2, 'a', std::unique_ptr<D>(new D(3)));
89         T1 t1 = std::move(t0);
90         assert(std::get<0>(t1) == 2);
91         assert(std::get<1>(t1) == int('a'));
92         assert(std::get<2>(t1)->id_ == 3);
93     }
94     {
95         std::tuple<int> t1(42);
96         std::tuple<Explicit> t2(std::move(t1));
97         assert(std::get<0>(t2).value == 42);
98     }
99     {
100         std::tuple<int> t1(42);
101         std::tuple<Implicit> t2 = std::move(t1);
102         assert(std::get<0>(t2).value == 42);
103     }
104 }
105