xref: /llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/move.pass.cpp (revision c281a7a19fbbf229334f595e879e0fed42613264)
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(tuple&& u);
15 
16 #include <tuple>
17 #include <utility>
18 #include <cassert>
19 
20 #include "MoveOnly.h"
21 
22 struct ConstructsWithTupleLeaf
23 {
24     ConstructsWithTupleLeaf() {}
25 
26     ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); }
27     ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {}
28 
29     template <class T>
30     ConstructsWithTupleLeaf(T t)
31     { assert(false); }
32 };
33 
34 int main()
35 {
36     {
37         typedef std::tuple<> T;
38         T t0;
39         T t = std::move(t0);
40         ((void)t); // Prevent unused warning
41     }
42     {
43         typedef std::tuple<MoveOnly> T;
44         T t0(MoveOnly(0));
45         T t = std::move(t0);
46         assert(std::get<0>(t) == 0);
47     }
48     {
49         typedef std::tuple<MoveOnly, MoveOnly> T;
50         T t0(MoveOnly(0), MoveOnly(1));
51         T t = std::move(t0);
52         assert(std::get<0>(t) == 0);
53         assert(std::get<1>(t) == 1);
54     }
55     {
56         typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
57         T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
58         T t = std::move(t0);
59         assert(std::get<0>(t) == 0);
60         assert(std::get<1>(t) == 1);
61         assert(std::get<2>(t) == 2);
62     }
63     // A bug in tuple caused __tuple_leaf to use its explicit converting constructor
64     //  as its move constructor. This tests that ConstructsWithTupleLeaf is not called
65     // (w/ __tuple_leaf)
66     {
67         typedef std::tuple<ConstructsWithTupleLeaf> d_t;
68         d_t d((ConstructsWithTupleLeaf()));
69         d_t d2(static_cast<d_t &&>(d));
70     }
71 }
72