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 | // tuple(tuple&& 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 <cassert> |
| 21 | |
Marshall Clow | df00d5e | 2015-01-28 21:22:53 +0000 | [diff] [blame] | 22 | #include "MoveOnly.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | |
Eric Fiselier | 9020c08 | 2014-07-24 18:48:34 +0000 | [diff] [blame] | 24 | struct ConstructsWithTupleLeaf |
| 25 | { |
| 26 | ConstructsWithTupleLeaf() {} |
| 27 | |
| 28 | ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); } |
| 29 | ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} |
| 30 | |
| 31 | template <class T> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 32 | ConstructsWithTupleLeaf(T t) |
| 33 | { assert(false); } |
Eric Fiselier | 9020c08 | 2014-07-24 18:48:34 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | int main() |
| 37 | { |
| 38 | { |
| 39 | typedef std::tuple<> T; |
| 40 | T t0; |
| 41 | T t = std::move(t0); |
Eric Fiselier | 75fdf0e | 2015-02-05 20:28:37 +0000 | [diff] [blame] | 42 | ((void)t); // Prevent unused warning |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | } |
| 44 | { |
| 45 | typedef std::tuple<MoveOnly> T; |
| 46 | T t0(MoveOnly(0)); |
| 47 | T t = std::move(t0); |
| 48 | assert(std::get<0>(t) == 0); |
| 49 | } |
| 50 | { |
| 51 | typedef std::tuple<MoveOnly, MoveOnly> T; |
| 52 | T t0(MoveOnly(0), MoveOnly(1)); |
| 53 | T t = std::move(t0); |
| 54 | assert(std::get<0>(t) == 0); |
| 55 | assert(std::get<1>(t) == 1); |
| 56 | } |
| 57 | { |
| 58 | typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; |
| 59 | T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); |
| 60 | T t = std::move(t0); |
| 61 | assert(std::get<0>(t) == 0); |
| 62 | assert(std::get<1>(t) == 1); |
| 63 | assert(std::get<2>(t) == 2); |
| 64 | } |
Eric Fiselier | 9020c08 | 2014-07-24 18:48:34 +0000 | [diff] [blame] | 65 | // A bug in tuple caused __tuple_leaf to use its explicit converting constructor |
| 66 | // as its move constructor. This tests that ConstructsWithTupleLeaf is not called |
| 67 | // (w/ __tuple_leaf) |
| 68 | { |
| 69 | typedef std::tuple<ConstructsWithTupleLeaf> d_t; |
| 70 | d_t d((ConstructsWithTupleLeaf())); |
| 71 | d_t d2(static_cast<d_t &&>(d)); |
| 72 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | } |