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 U1, class U2> 12 // constexpr const tuple& operator=(const pair<U1, U2>& u) const; 13 // 14 // - sizeof...(Types) is 2, 15 // - is_assignable_v<const T1&, const U1&> is true, and 16 // - is_assignable_v<const T2&, const U2&> is true 17 18 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 19 20 #include <cassert> 21 #include <tuple> 22 #include <type_traits> 23 #include <utility> 24 25 #include "test_macros.h" 26 #include "types.h" 27 28 // test constraints 29 30 // sizeof...(Types) != 2, 31 static_assert(std::is_assignable_v<const std::tuple<int&, int&>&, const std::pair<int&, int&>&>); 32 static_assert(!std::is_assignable_v<const std::tuple<int&>&, const std::pair<int&, int&>&>); 33 static_assert(!std::is_assignable_v<const std::tuple<int&, int&, int&>&, const std::pair<int&, int&>&>); 34 35 static_assert(std::is_assignable_v<const std::tuple<AssignableFrom<ConstCopyAssign>, ConstCopyAssign>&, 36 const std::pair<ConstCopyAssign, ConstCopyAssign>&>); 37 38 // is_assignable_v<const T1&, const U1&> is false 39 static_assert(!std::is_assignable_v<const std::tuple<AssignableFrom<CopyAssign>, ConstCopyAssign>&, 40 const std::pair<CopyAssign, ConstCopyAssign>&>); 41 42 // is_assignable_v<const T2&, const U2&> is false 43 static_assert(!std::is_assignable_v<const std::tuple<AssignableFrom<ConstCopyAssign>, AssignableFrom<CopyAssign>>&, 44 const std::tuple<ConstCopyAssign, CopyAssign>&>); 45 46 constexpr bool test() { 47 // reference types 48 { 49 int i1 = 1; 50 int i2 = 2; 51 long j1 = 3; 52 long j2 = 4; 53 const std::pair<int&, int&> t1{i1, i2}; 54 const std::tuple<long&, long&> t2{j1, j2}; 55 t2 = t1; 56 assert(std::get<0>(t2) == 1); 57 assert(std::get<1>(t2) == 2); 58 } 59 60 // user defined const copy assignment 61 { 62 const std::pair<ConstCopyAssign, ConstCopyAssign> t1{1, 2}; 63 const std::tuple<AssignableFrom<ConstCopyAssign>, ConstCopyAssign> t2{3, 4}; 64 t2 = t1; 65 assert(std::get<0>(t2).v.val == 1); 66 assert(std::get<1>(t2).val == 2); 67 } 68 69 // make sure the right assignment operator of the type in the tuple is used 70 { 71 std::pair<TracedAssignment, TracedAssignment> t1{}; 72 const std::tuple<AssignableFrom<TracedAssignment>, AssignableFrom<TracedAssignment>> t2{}; 73 t2 = t1; 74 assert(std::get<0>(t2).v.constCopyAssign == 1); 75 assert(std::get<1>(t2).v.constCopyAssign == 1); 76 } 77 78 return true; 79 } 80 81 int main(int, char**) { 82 test(); 83 84 // gcc cannot have mutable member in constant expression 85 #if !defined(TEST_COMPILER_GCC) 86 static_assert(test()); 87 #endif 88 return 0; 89 } 90