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