Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <tuple> |
| 11 | |
| 12 | // template <class... Types> class tuple; |
| 13 | |
| 14 | // template <class... UTypes> tuple(const tuple<UTypes...>& u); |
| 15 | |
Eric Fiselier | f063052 | 2015-02-19 02:10:42 +0000 | [diff] [blame] | 16 | // UNSUPPORTED: c++98, c++03 |
| 17 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | #include <tuple> |
Marshall Clow | 6b913d7 | 2015-01-09 20:25:52 +0000 | [diff] [blame] | 19 | #include <utility> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <cassert> |
| 22 | |
| 23 | struct B |
| 24 | { |
| 25 | int id_; |
| 26 | |
| 27 | explicit B(int i) : id_(i) {} |
| 28 | }; |
| 29 | |
| 30 | struct D |
| 31 | : B |
| 32 | { |
| 33 | explicit D(int i) : B(i) {} |
| 34 | }; |
| 35 | |
Marshall Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 36 | #if _LIBCPP_STD_VER > 11 |
| 37 | |
| 38 | struct 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 | |
| 46 | struct 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | int 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 Clow | da0a0e8 | 2013-07-22 16:02:19 +0000 | [diff] [blame] | 65 | #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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 81 | { |
| 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 Hinnant | 9932489 | 2013-04-14 00:01:13 +0000 | [diff] [blame] | 109 | { |
| 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 118 | } |