blob: 5ad4f9227f4814a8b2f67f861e19ae401945fea5 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <tuple>
11
12// template <class... Types> class tuple;
13
14// template <class... UTypes> tuple(const tuple<UTypes...>& u);
15
Eric Fiselierf0630522015-02-19 02:10:42 +000016// UNSUPPORTED: c++98, c++03
17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000018#include <tuple>
Marshall Clow6b913d72015-01-09 20:25:52 +000019#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020#include <string>
21#include <cassert>
22
23struct B
24{
25 int id_;
26
27 explicit B(int i) : id_(i) {}
28};
29
30struct D
31 : B
32{
33 explicit D(int i) : B(i) {}
34};
35
Marshall Clowda0a0e82013-07-22 16:02:19 +000036#if _LIBCPP_STD_VER > 11
37
38struct A
39{
40 int id_;
41
42 constexpr A(int i) : id_(i) {}
43 friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;}
44};
45
46struct C
47{
48 int id_;
49
50 constexpr explicit C(int i) : id_(i) {}
51 friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;}
52};
53
54#endif
55
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056int main()
57{
58 {
59 typedef std::tuple<double> T0;
60 typedef std::tuple<int> T1;
61 T0 t0(2.5);
62 T1 t1 = t0;
63 assert(std::get<0>(t1) == 2);
64 }
Marshall Clowda0a0e82013-07-22 16:02:19 +000065#if _LIBCPP_STD_VER > 11
66 {
67 typedef std::tuple<double> T0;
68 typedef std::tuple<A> T1;
69 constexpr T0 t0(2.5);
70 constexpr T1 t1 = t0;
71 static_assert(std::get<0>(t1) == 2, "");
72 }
73 {
74 typedef std::tuple<int> T0;
75 typedef std::tuple<C> T1;
76 constexpr T0 t0(2);
77 constexpr T1 t1{t0};
78 static_assert(std::get<0>(t1) == C(2), "");
79 }
80#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000081 {
82 typedef std::tuple<double, char> T0;
83 typedef std::tuple<int, int> T1;
84 T0 t0(2.5, 'a');
85 T1 t1 = t0;
86 assert(std::get<0>(t1) == 2);
87 assert(std::get<1>(t1) == int('a'));
88 }
89 {
90 typedef std::tuple<double, char, D> T0;
91 typedef std::tuple<int, int, B> T1;
92 T0 t0(2.5, 'a', D(3));
93 T1 t1 = t0;
94 assert(std::get<0>(t1) == 2);
95 assert(std::get<1>(t1) == int('a'));
96 assert(std::get<2>(t1).id_ == 3);
97 }
98 {
99 D d(3);
100 typedef std::tuple<double, char, D&> T0;
101 typedef std::tuple<int, int, B&> T1;
102 T0 t0(2.5, 'a', d);
103 T1 t1 = t0;
104 d.id_ = 2;
105 assert(std::get<0>(t1) == 2);
106 assert(std::get<1>(t1) == int('a'));
107 assert(std::get<2>(t1).id_ == 2);
108 }
Howard Hinnant99324892013-04-14 00:01:13 +0000109 {
110 typedef std::tuple<double, char, int> T0;
111 typedef std::tuple<int, int, B> T1;
112 T0 t0(2.5, 'a', 3);
113 T1 t1(t0);
114 assert(std::get<0>(t1) == 2);
115 assert(std::get<1>(t1) == int('a'));
116 assert(std::get<2>(t1).id_ == 3);
117 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118}