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// <map>
10
11// class multimap
12
13// multimap& operator=(const multimap& m);
14
15#include <map>
16#include <cassert>
17
18#include "test_macros.h"
19#include "../../../test_compare.h"
20#include "test_allocator.h"
21#include "min_allocator.h"
22
23int main(int, char**) {
24 {
25 typedef std::pair<const int, double> V;
26 V ar[] = {
27 V(1, 1),
28 V(1, 1.5),
29 V(1, 2),
30 V(2, 1),
31 V(2, 1.5),
32 V(2, 2),
33 V(3, 1),
34 V(3, 1.5),
35 V(3, 2),
36 };
37 typedef test_less<int> C;
38 typedef test_allocator<V> A;
39 std::multimap<int, double, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(2));
40 std::multimap<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]) / 2, C(3), A(7));
41 m = mo;
42 assert(m == mo);
43 assert(m.get_allocator() == A(7));
44 assert(m.key_comp() == C(5));
45
46 assert(mo.get_allocator() == A(2));
47 assert(mo.key_comp() == C(5));
48 }
49 {
50 typedef std::pair<const int, double> V;
51 const V ar[] = {
52 V(1, 1),
53 V(1, 1.5),
54 V(1, 2),
55 V(2, 1),
56 V(2, 1.5),
57 V(2, 2),
58 V(3, 1),
59 V(3, 1.5),
60 V(3, 2),
61 };
62 std::multimap<int, double> m(ar, ar + sizeof(ar) / sizeof(ar[0]));
63 std::multimap<int, double>* p = &m;
64 m = *p;
65 assert(m.size() == sizeof(ar) / sizeof(ar[0]));
66 assert(std::equal(m.begin(), m.end(), ar));
67 }
68 {
69 typedef std::pair<const int, double> V;
70 V ar[] = {
71 V(1, 1),
72 V(1, 1.5),
73 V(1, 2),
74 V(2, 1),
75 V(2, 1.5),
76 V(2, 2),
77 V(3, 1),
78 V(3, 1.5),
79 V(3, 2),
80 };
81 typedef test_less<int> C;
82 typedef other_allocator<V> A;
83 std::multimap<int, double, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(2));
84 std::multimap<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]) / 2, C(3), A(7));
85 m = mo;
86 assert(m == mo);
87 assert(m.get_allocator() == A(2));
88 assert(m.key_comp() == C(5));
89
90 assert(mo.get_allocator() == A(2));
91 assert(mo.key_comp() == C(5));
92 }
93#if TEST_STD_VER >= 11
94 {
95 typedef std::pair<const int, double> V;
96 V ar[] = {
97 V(1, 1),
98 V(1, 1.5),
99 V(1, 2),
100 V(2, 1),
101 V(2, 1.5),
102 V(2, 2),
103 V(3, 1),
104 V(3, 1.5),
105 V(3, 2),
106 };
107 typedef test_less<int> C;
108 typedef min_allocator<V> A;
109 std::multimap<int, double, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A());
110 std::multimap<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]) / 2, C(3), A());
111 m = mo;
112 assert(m == mo);
113 assert(m.get_allocator() == A());
114 assert(m.key_comp() == C(5));
115
116 assert(mo.get_allocator() == A());
117 assert(mo.key_comp() == C(5));
118 }
119#endif
120
121 return 0;
122}
123

source code of libcxx/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp