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>
15 // tuple& operator=(const tuple<UTypes...>& u);
16
17 // UNSUPPORTED: c++98, c++03
18
19 #include <tuple>
20 #include <string>
21 #include <cassert>
22
23 struct B
24 {
25 int id_;
26
BB27 explicit B(int i = 0) : id_(i) {}
28 };
29
30 struct D
31 : B
32 {
DD33 explicit D(int i = 0) : B(i) {}
34 };
35
main()36 int main()
37 {
38 {
39 typedef std::tuple<long> T0;
40 typedef std::tuple<long long> T1;
41 T0 t0(2);
42 T1 t1;
43 t1 = t0;
44 assert(std::get<0>(t1) == 2);
45 }
46 {
47 typedef std::tuple<long, char> T0;
48 typedef std::tuple<long long, int> T1;
49 T0 t0(2, 'a');
50 T1 t1;
51 t1 = t0;
52 assert(std::get<0>(t1) == 2);
53 assert(std::get<1>(t1) == int('a'));
54 }
55 {
56 typedef std::tuple<long, char, D> T0;
57 typedef std::tuple<long long, int, B> T1;
58 T0 t0(2, 'a', D(3));
59 T1 t1;
60 t1 = t0;
61 assert(std::get<0>(t1) == 2);
62 assert(std::get<1>(t1) == int('a'));
63 assert(std::get<2>(t1).id_ == 3);
64 }
65 {
66 D d(3);
67 D d2(2);
68 typedef std::tuple<long, char, D&> T0;
69 typedef std::tuple<long long, int, B&> T1;
70 T0 t0(2, 'a', d2);
71 T1 t1(1, 'b', d);
72 t1 = t0;
73 assert(std::get<0>(t1) == 2);
74 assert(std::get<1>(t1) == int('a'));
75 assert(std::get<2>(t1).id_ == 2);
76 }
77 {
78 // Test that tuple evaluates correctly applies an lvalue reference
79 // before evaluating is_assignable (ie 'is_assignable<int&, int&>')
80 // instead of evaluating 'is_assignable<int&&, int&>' which is false.
81 int x = 42;
82 int y = 43;
83 std::tuple<int&&> t(std::move(x));
84 std::tuple<int&> t2(y);
85 t = t2;
86 assert(std::get<0>(t) == 43);
87 assert(&std::get<0>(t) == &x);
88 }
89 }
90