Home | History | Annotate | Download | only in tuple.cnstr
      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 // UNSUPPORTED: c++98, c++03
     17 
     18 #include <tuple>
     19 #include <utility>
     20 #include <cassert>
     21 
     22 #include "MoveOnly.h"
     23 
     24 struct ConstructsWithTupleLeaf
     25 {
     26     ConstructsWithTupleLeaf() {}
     27 
     28     ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); }
     29     ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {}
     30 
     31     template <class T>
     32     ConstructsWithTupleLeaf(T t)
     33     { assert(false); }
     34 };
     35 
     36 int main()
     37 {
     38     {
     39         typedef std::tuple<> T;
     40         T t0;
     41         T t = std::move(t0);
     42         ((void)t); // Prevent unused warning
     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     }
     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     }
     73 }
     74