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 // constexpr const tuple& operator=(const tuple&) const; 12 // 13 // Constraints: (is_copy_assignable_v<const Types> && ...) is true. 14 15 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 16 17 // test constraints 18 19 #include <cassert> 20 #include <tuple> 21 #include <type_traits> 22 23 #include "test_macros.h" 24 #include "types.h" 25 26 static_assert(!std::is_assignable_v<const std::tuple<int>&, const std::tuple<int>&>); 27 static_assert(std::is_assignable_v<const std::tuple<int&>&, const std::tuple<int&>&>); 28 static_assert(std::is_assignable_v<const std::tuple<int&, int&>&, const std::tuple<int&, int&>&>); 29 static_assert(!std::is_assignable_v<const std::tuple<int&, int>&, const std::tuple<int&, int>&>); 30 static_assert(std::is_assignable_v<const std::tuple<ConstCopyAssign>&, const std::tuple<ConstCopyAssign>&>); 31 static_assert(!std::is_assignable_v<const std::tuple<CopyAssign>&, const std::tuple<CopyAssign>&>); 32 static_assert(!std::is_assignable_v<const std::tuple<ConstMoveAssign>&, const std::tuple<ConstMoveAssign>&>); 33 static_assert(!std::is_assignable_v<const std::tuple<MoveAssign>&, const std::tuple<MoveAssign>&>); 34 35 constexpr bool test() { 36 // reference types 37 { 38 int i1 = 1; 39 int i2 = 2; 40 double d1 = 3.0; 41 double d2 = 5.0; 42 const std::tuple<int&, double&> t1{i1, d1}; 43 const std::tuple<int&, double&> t2{i2, d2}; 44 t2 = t1; 45 assert(std::get<0>(t2) == 1); 46 assert(std::get<1>(t2) == 3.0); 47 } 48 49 // user defined const copy assignment 50 { 51 const std::tuple<ConstCopyAssign> t1{1}; 52 const std::tuple<ConstCopyAssign> t2{2}; 53 t2 = t1; 54 assert(std::get<0>(t2).val == 1); 55 } 56 57 // make sure the right assignment operator of the type in the tuple is used 58 { 59 std::tuple<TracedAssignment, const TracedAssignment> t1{}; 60 const std::tuple<TracedAssignment, const TracedAssignment> t2{}; 61 t2 = t1; 62 assert(std::get<0>(t2).constCopyAssign == 1); 63 assert(std::get<1>(t2).constCopyAssign == 1); 64 } 65 66 return true; 67 } 68 69 int main(int, char**) { 70 test(); 71 72 // gcc cannot have mutable member in constant expression 73 #if !defined(TEST_COMPILER_GCC) 74 static_assert(test()); 75 #endif 76 return 0; 77 } 78