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++03
16
17#include <tuple>
18#include <string>
19#include <memory>
20#include <cassert>
21
22#include "test_macros.h"
23
24struct Explicit {
25 int value;
26 explicit Explicit(int x) : value(x) {}
27};
28
29struct Implicit {
30 int value;
31 Implicit(int x) : value(x) {}
32};
33
34struct B
35{
36 int id_;
37
38 explicit B(int i) : id_(i) {}
39 B(const B&) = default;
40 B& operator=(const B&) = default;
41 virtual ~B() {}
42};
43
44struct D
45 : B
46{
47 explicit D(int i) : B(i) {}
48};
49
50struct BonkersBananas {
51 template <class T>
52 operator T() &&;
53 template <class T, class = void>
54 explicit operator T() && = delete;
55};
56
57void test_bonkers_bananas_conversion() {
58 using ReturnType = std::tuple<int, int>;
59 static_assert(std::is_convertible<BonkersBananas, ReturnType>(), "");
60 static_assert(!std::is_constructible<ReturnType, BonkersBananas>(), "");
61
62}
63
64int main(int, char**)
65{
66 {
67 typedef std::tuple<long> T0;
68 typedef std::tuple<long long> T1;
69 T0 t0(2);
70 T1 t1 = std::move(t0);
71 assert(std::get<0>(t1) == 2);
72 }
73 {
74 typedef std::tuple<long, char> T0;
75 typedef std::tuple<long long, int> T1;
76 T0 t0(2, 'a');
77 T1 t1 = std::move(t0);
78 assert(std::get<0>(t1) == 2);
79 assert(std::get<1>(t1) == int('a'));
80 }
81 {
82 typedef std::tuple<long, char, D> T0;
83 typedef std::tuple<long long, int, B> T1;
84 T0 t0(2, 'a', D(3));
85 T1 t1 = std::move(t0);
86 assert(std::get<0>(t1) == 2);
87 assert(std::get<1>(t1) == int('a'));
88 assert(std::get<2>(t1).id_ == 3);
89 }
90 {
91 D d(3);
92 typedef std::tuple<long, char, D&> T0;
93 typedef std::tuple<long long, int, B&> T1;
94 T0 t0(2, 'a', d);
95 T1 t1 = std::move(t0);
96 d.id_ = 2;
97 assert(std::get<0>(t1) == 2);
98 assert(std::get<1>(t1) == int('a'));
99 assert(std::get<2>(t1).id_ == 2);
100 }
101 {
102 typedef std::tuple<long, char, std::unique_ptr<D>> T0;
103 typedef std::tuple<long long, int, std::unique_ptr<B>> T1;
104 T0 t0(2, 'a', std::unique_ptr<D>(new D(3)));
105 T1 t1 = std::move(t0);
106 assert(std::get<0>(t1) == 2);
107 assert(std::get<1>(t1) == int('a'));
108 assert(std::get<2>(t1)->id_ == 3);
109 }
110 {
111 std::tuple<int> t1(42);
112 std::tuple<Explicit> t2(std::move(t1));
113 assert(std::get<0>(t2).value == 42);
114 }
115 {
116 std::tuple<int> t1(42);
117 std::tuple<Implicit> t2 = std::move(t1);
118 assert(std::get<0>(t2).value == 42);
119 }
120
121 return 0;
122}
123

source code of libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/convert_move.pass.cpp