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 // template <class... UTypes>
     15 //   explicit tuple(UTypes&&... u);
     16 
     17 /*
     18     This is testing an extension whereby only Types having an explicit conversion
     19     from UTypes are bound by the explicit tuple constructor.
     20 */
     21 
     22 #include <tuple>
     23 #include <cassert>
     24 
     25 class MoveOnly
     26 {
     27     MoveOnly(const MoveOnly&);
     28     MoveOnly& operator=(const MoveOnly&);
     29 
     30     int data_;
     31 public:
     32     explicit MoveOnly(int data = 1) : data_(data) {}
     33     MoveOnly(MoveOnly&& x)
     34         : data_(x.data_) {x.data_ = 0;}
     35     MoveOnly& operator=(MoveOnly&& x)
     36         {data_ = x.data_; x.data_ = 0; return *this;}
     37 
     38     int get() const {return data_;}
     39 
     40     bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
     41     bool operator< (const MoveOnly& x) const {return data_ <  x.data_;}
     42 };
     43 
     44 int main()
     45 {
     46     {
     47         std::tuple<MoveOnly> t = 1;
     48     }
     49 }
     50