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=(pair<U1, U2>&& u) const; |
13 | // |
14 | // - sizeof...(Types) is 2, |
15 | // - is_assignable_v<const T1&, U1> is true, and |
16 | // - is_assignable_v<const T2&, 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 "copy_move_types.h" |
27 | |
28 | // test constraints |
29 | |
30 | // sizeof...(Types) != 2, |
31 | static_assert(std::is_assignable_v<const std::tuple<int&, int&>&, std::pair<int&, int&>&&>); |
32 | static_assert(!std::is_assignable_v<const std::tuple<int&>&, std::pair<int&, int&>&&>); |
33 | static_assert(!std::is_assignable_v<const std::tuple<int&, int&, int&>&, std::pair<int&, int&>&&>); |
34 | |
35 | static_assert(std::is_assignable_v<const std::tuple<AssignableFrom<ConstMoveAssign>, ConstMoveAssign>&, |
36 | std::pair<ConstMoveAssign, ConstMoveAssign>&&>); |
37 | |
38 | // is_assignable_v<const T1&, U1> is false |
39 | static_assert(!std::is_assignable_v<const std::tuple<AssignableFrom<MoveAssign>, ConstMoveAssign>&, |
40 | std::pair<MoveAssign, ConstMoveAssign>&&>); |
41 | |
42 | // is_assignable_v<const T2&, U2> is false |
43 | static_assert(!std::is_assignable_v<const std::tuple<AssignableFrom<ConstMoveAssign>, AssignableFrom<MoveAssign>>&, |
44 | std::tuple<ConstMoveAssign, MoveAssign>&&>); |
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 | std::pair<int&, int&> t1{i1, i2}; |
54 | const std::tuple<long&, long&> t2{j1, j2}; |
55 | t2 = std::move(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 | std::pair<ConstMoveAssign, ConstMoveAssign> t1{1, 2}; |
63 | const std::tuple<AssignableFrom<ConstMoveAssign>, ConstMoveAssign> t2{3, 4}; |
64 | t2 = std::move(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 = std::move(t1); |
74 | assert(std::get<0>(t2).v.constMoveAssign == 1); |
75 | assert(std::get<1>(t2).v.constMoveAssign == 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 | |