1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
13 // template <class T1, class T2> struct pair
14 // template <class U1, class U2>
15 // constexpr const pair& operator=(pair<U1, U2>&& p) const;
20 #include "test_macros.h"
21 #include "copy_move_types.h"
24 // is_assignable<const first_type&, U1> is true and
25 // is_assignable<const second_type&, U2> is true.
28 static_assert( std::is_assignable_v
<const std::pair
<int&&, int&&>&,
29 std::pair
<long&&, long&&>&&>);
30 static_assert(!std::is_assignable_v
<const std::pair
<int, int>&,
31 std::pair
<long, long>&&>);
32 static_assert(!std::is_assignable_v
<const std::pair
<int, int&&>&,
33 std::pair
<long, long&&>&&>);
34 static_assert(!std::is_assignable_v
<const std::pair
<int&&, int>&,
35 std::pair
<long&&, long>&&>);
37 static_assert(std::is_assignable_v
<
38 const std::pair
<AssignableFrom
<ConstMoveAssign
>, AssignableFrom
<ConstMoveAssign
>>&,
39 std::pair
<ConstMoveAssign
, ConstMoveAssign
>&&>);
41 static_assert(!std::is_assignable_v
<
42 const std::pair
<AssignableFrom
<MoveAssign
>, AssignableFrom
<MoveAssign
>>&,
43 std::pair
<MoveAssign
, MoveAssign
>&&>);
46 constexpr bool test() {
53 std::pair
<int&&, int&&> p1
{std::move(i1
), std::move(i2
)};
54 const std::pair
<long&&, long&&> p2
{std::move(j1
), std::move(j2
)};
56 assert(p2
.first
== 1);
57 assert(p2
.second
== 2);
60 // user defined const move assignment
62 std::pair
<ConstMoveAssign
, ConstMoveAssign
> p1
{1, 2};
63 const std::pair
<AssignableFrom
<ConstMoveAssign
>, AssignableFrom
<ConstMoveAssign
>> p2
{3, 4};
65 assert(p2
.first
.v
.val
== 1);
66 assert(p2
.second
.v
.val
== 2);
69 // The correct assignment operator of the underlying type is used
71 std::pair
<TracedAssignment
, TracedAssignment
> t1
{};
72 const std::pair
<AssignableFrom
<TracedAssignment
>, AssignableFrom
<TracedAssignment
>> t2
{};
74 assert(t2
.first
.v
.constMoveAssign
== 1);
75 assert(t2
.second
.v
.constMoveAssign
== 1);
81 int main(int, char**) {
83 // gcc cannot have mutable member in constant expression
84 #if !defined(TEST_COMPILER_GCC)
85 static_assert(test());