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 U1, class U2> 14 // tuple& operator=(pair<U1, U2>&& u); 15 16 // UNSUPPORTED: c++03 17 18 #include <tuple> 19 #include <utility> 20 #include <memory> 21 #include <cassert> 22 23 #include "test_macros.h" 24 25 struct B 26 { 27 int id_; 28 29 explicit B(int i = 0) : id_(i) {} 30 31 virtual ~B() {} 32 }; 33 34 struct D 35 : B 36 { 37 explicit D(int i) : B(i) {} 38 }; 39 40 struct NonAssignable 41 { 42 NonAssignable& operator=(NonAssignable const&) = delete; 43 NonAssignable& operator=(NonAssignable&&) = delete; 44 }; 45 46 struct NothrowMoveAssignable 47 { 48 NothrowMoveAssignable& operator=(NothrowMoveAssignable&&) noexcept { return *this; } 49 }; 50 51 struct PotentiallyThrowingMoveAssignable 52 { 53 PotentiallyThrowingMoveAssignable& operator=(PotentiallyThrowingMoveAssignable&&) { return *this; } 54 }; 55 56 int main(int, char**) 57 { 58 { 59 typedef std::pair<long, std::unique_ptr<D>> T0; 60 typedef std::tuple<long long, std::unique_ptr<B>> T1; 61 T0 t0(2, std::unique_ptr<D>(new D(3))); 62 T1 t1; 63 t1 = std::move(t0); 64 assert(std::get<0>(t1) == 2); 65 assert(std::get<1>(t1)->id_ == 3); 66 } 67 { 68 using T = std::tuple<int, NonAssignable>; 69 using P = std::pair<int, NonAssignable>; 70 static_assert(!std::is_assignable<T&, P&&>::value, ""); 71 } 72 { 73 using T = std::tuple<int, int, int>; 74 using P = std::pair<int, int>; 75 static_assert(!std::is_assignable<T&, P&&>::value, ""); 76 } 77 { 78 typedef std::tuple<NothrowMoveAssignable, long> Tuple; 79 typedef std::pair<NothrowMoveAssignable, int> Pair; 80 static_assert(std::is_nothrow_assignable<Tuple&, Pair&&>::value, ""); 81 static_assert(!std::is_assignable<Tuple&, Pair const&&>::value, ""); 82 } 83 { 84 typedef std::tuple<PotentiallyThrowingMoveAssignable, long> Tuple; 85 typedef std::pair<PotentiallyThrowingMoveAssignable, int> Pair; 86 static_assert(std::is_assignable<Tuple&, Pair&&>::value, ""); 87 static_assert(!std::is_nothrow_assignable<Tuple&, Pair&&>::value, ""); 88 static_assert(!std::is_assignable<Tuple&, Pair const&&>::value, ""); 89 } 90 91 return 0; 92 } 93