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 // tuple& operator=(const tuple& u);
15
16 // UNSUPPORTED: c++98, c++03
17
18 #include <tuple>
19 #include <memory>
20 #include <string>
21 #include <cassert>
22
23 #include "test_macros.h"
24
25 struct NonAssignable {
26 NonAssignable& operator=(NonAssignable const&) = delete;
27 NonAssignable& operator=(NonAssignable&&) = delete;
28 };
29 struct CopyAssignable {
30 CopyAssignable& operator=(CopyAssignable const&) = default;
31 CopyAssignable& operator=(CopyAssignable &&) = delete;
32 };
33 static_assert(std::is_copy_assignable<CopyAssignable>::value, "");
34 struct MoveAssignable {
35 MoveAssignable& operator=(MoveAssignable const&) = delete;
36 MoveAssignable& operator=(MoveAssignable&&) = default;
37 };
38
main()39 int main()
40 {
41 {
42 typedef std::tuple<> T;
43 T t0;
44 T t;
45 t = t0;
46 }
47 {
48 typedef std::tuple<int> T;
49 T t0(2);
50 T t;
51 t = t0;
52 assert(std::get<0>(t) == 2);
53 }
54 {
55 typedef std::tuple<int, char> T;
56 T t0(2, 'a');
57 T t;
58 t = t0;
59 assert(std::get<0>(t) == 2);
60 assert(std::get<1>(t) == 'a');
61 }
62 {
63 typedef std::tuple<int, char, std::string> T;
64 const T t0(2, 'a', "some text");
65 T t;
66 t = t0;
67 assert(std::get<0>(t) == 2);
68 assert(std::get<1>(t) == 'a');
69 assert(std::get<2>(t) == "some text");
70 }
71 {
72 // test reference assignment.
73 using T = std::tuple<int&, int&&>;
74 int x = 42;
75 int y = 100;
76 int x2 = -1;
77 int y2 = 500;
78 T t(x, std::move(y));
79 T t2(x2, std::move(y2));
80 t = t2;
81 assert(std::get<0>(t) == x2);
82 assert(&std::get<0>(t) == &x);
83 assert(std::get<1>(t) == y2);
84 assert(&std::get<1>(t) == &y);
85 }
86 {
87 // test that the implicitly generated copy assignment operator
88 // is properly deleted
89 using T = std::tuple<std::unique_ptr<int>>;
90 static_assert(!std::is_copy_assignable<T>::value, "");
91 }
92 {
93 using T = std::tuple<int, NonAssignable>;
94 static_assert(!std::is_copy_assignable<T>::value, "");
95 }
96 {
97 using T = std::tuple<int, CopyAssignable>;
98 static_assert(std::is_copy_assignable<T>::value, "");
99 }
100 {
101 using T = std::tuple<int, MoveAssignable>;
102 static_assert(!std::is_copy_assignable<T>::value, "");
103 }
104 }
105