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 // UNSUPPORTED: c++03
10
11 // <utility>
12
13 // template <class T1, class T2> struct pair
14
15 // pair(pair&&) = default;
16
17 #include <utility>
18 #include <memory>
19 #include <cassert>
20
21 #include "test_macros.h"
22
23 struct Dummy {
24 Dummy(Dummy const&) = delete;
25 Dummy(Dummy &&) = default;
26 };
27
28 struct NotCopyOrMoveConstructible {
29 NotCopyOrMoveConstructible() = default;
30 NotCopyOrMoveConstructible(NotCopyOrMoveConstructible const&) = delete;
31 NotCopyOrMoveConstructible(NotCopyOrMoveConstructible&&) = delete;
32 };
33
main(int,char **)34 int main(int, char**)
35 {
36 {
37 typedef std::pair<int, short> P1;
38 static_assert(std::is_move_constructible<P1>::value, "");
39 P1 p1(3, static_cast<short>(4));
40 P1 p2 = std::move(p1);
41 assert(p2.first == 3);
42 assert(p2.second == 4);
43 }
44 {
45 using P = std::pair<Dummy, int>;
46 static_assert(!std::is_copy_constructible<P>::value, "");
47 static_assert(std::is_move_constructible<P>::value, "");
48 }
49 {
50 // When constructing a pair containing a reference, we only bind the
51 // reference, so it doesn't matter whether the type is or isn't
52 // copy/move constructible.
53 {
54 using P = std::pair<NotCopyOrMoveConstructible&, int>;
55 static_assert(std::is_move_constructible<P>::value, "");
56
57 NotCopyOrMoveConstructible obj;
58 P p2{obj, 3};
59 P p1(std::move(p2));
60 assert(&p1.first == &obj);
61 assert(&p2.first == &obj);
62 }
63 {
64 using P = std::pair<NotCopyOrMoveConstructible&&, int>;
65 static_assert(std::is_move_constructible<P>::value, "");
66
67 NotCopyOrMoveConstructible obj;
68 P p2{std::move(obj), 3};
69 P p1(std::move(p2));
70 assert(&p1.first == &obj);
71 assert(&p2.first == &obj);
72 }
73 }
74
75 return 0;
76 }
77