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 //===----------------------------------------------------------------------===//
13 // template <class T1, class T2> struct pair
15 // pair(pair&&) = default;
19 #include <type_traits>
22 #include "test_macros.h"
25 Dummy(Dummy
const&) = delete;
26 Dummy(Dummy
&&) = default;
29 struct NotCopyOrMoveConstructible
{
30 NotCopyOrMoveConstructible() = default;
31 NotCopyOrMoveConstructible(NotCopyOrMoveConstructible
const&) = delete;
32 NotCopyOrMoveConstructible(NotCopyOrMoveConstructible
&&) = delete;
38 typedef std::pair
<int, short> P1
;
39 static_assert(std::is_move_constructible
<P1
>::value
, "");
40 P1
p1(3, static_cast<short>(4));
41 P1 p2
= std::move(p1
);
42 assert(p2
.first
== 3);
43 assert(p2
.second
== 4);
46 using P
= std::pair
<Dummy
, int>;
47 static_assert(!std::is_copy_constructible
<P
>::value
, "");
48 static_assert(std::is_move_constructible
<P
>::value
, "");
51 // When constructing a pair containing a reference, we only bind the
52 // reference, so it doesn't matter whether the type is or isn't
53 // copy/move constructible.
55 using P
= std::pair
<NotCopyOrMoveConstructible
&, int>;
56 static_assert(std::is_move_constructible
<P
>::value
, "");
58 NotCopyOrMoveConstructible obj
;
61 assert(&p1
.first
== &obj
);
62 assert(&p2
.first
== &obj
);
65 using P
= std::pair
<NotCopyOrMoveConstructible
&&, int>;
66 static_assert(std::is_move_constructible
<P
>::value
, "");
68 NotCopyOrMoveConstructible obj
;
69 P p2
{std::move(obj
), 3};
71 assert(&p1
.first
== &obj
);
72 assert(&p2
.first
== &obj
);