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 // template<class U, class V> pair& operator=(tuple<U, V>&& p);
16
17 #include <utility>
18 #include <tuple>
19 #include <array>
20 #include <memory>
21 #include <cassert>
22
23 #include "archetypes.h"
24
main(int,char **)25 int main(int, char**)
26 {
27 using C = TestTypes::TestType;
28 {
29 using P = std::pair<int, C>;
30 using T = std::tuple<int, C>;
31 T t(42, C{42});
32 P p(101, C{101});
33 C::reset_constructors();
34 p = t;
35 assert(C::constructed == 0);
36 assert(C::assigned == 1);
37 assert(C::copy_assigned == 1);
38 assert(C::move_assigned == 0);
39 assert(p.first == 42);
40 assert(p.second.value == 42);
41 }
42 {
43 using P = std::pair<int, C>;
44 using T = std::tuple<int, C>;
45 T t(42, -42);
46 P p(101, 101);
47 C::reset_constructors();
48 p = std::move(t);
49 assert(C::constructed == 0);
50 assert(C::assigned == 1);
51 assert(C::copy_assigned == 0);
52 assert(C::move_assigned == 1);
53 assert(p.first == 42);
54 assert(p.second.value == -42);
55 }
56 {
57 using P = std::pair<C, C>;
58 using T = std::array<C, 2>;
59 T t = {42, -42};
60 P p{101, 101};
61 C::reset_constructors();
62 p = t;
63 assert(C::constructed == 0);
64 assert(C::assigned == 2);
65 assert(C::copy_assigned == 2);
66 assert(C::move_assigned == 0);
67 assert(p.first.value == 42);
68 assert(p.second.value == -42);
69 }
70 {
71 using P = std::pair<C, C>;
72 using T = std::array<C, 2>;
73 T t = {42, -42};
74 P p{101, 101};
75 C::reset_constructors();
76 p = t;
77 assert(C::constructed == 0);
78 assert(C::assigned == 2);
79 assert(C::copy_assigned == 2);
80 assert(C::move_assigned == 0);
81 assert(p.first.value == 42);
82 assert(p.second.value == -42);
83 }
84 {
85 using P = std::pair<C, C>;
86 using T = std::array<C, 2>;
87 T t = {42, -42};
88 P p{101, 101};
89 C::reset_constructors();
90 p = std::move(t);
91 assert(C::constructed == 0);
92 assert(C::assigned == 2);
93 assert(C::copy_assigned == 0);
94 assert(C::move_assigned == 2);
95 assert(p.first.value == 42);
96 assert(p.second.value == -42);
97 }
98
99 return 0;
100 }
101