llvm-project
127 строк · 3.4 Кб
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{
26typedef std::pair<const int, double> V;
27V ar[] =
28{
29V(1, 1),
30V(1, 1.5),
31V(1, 2),
32V(2, 1),
33V(2, 1.5),
34V(2, 2),
35V(3, 1),
36V(3, 1.5),
37V(3, 2),
38};
39typedef test_less<int> C;
40typedef test_allocator<V> A;
41std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
42std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
43m = mo;
44assert(m == mo);
45assert(m.get_allocator() == A(7));
46assert(m.key_comp() == C(5));
47
48assert(mo.get_allocator() == A(2));
49assert(mo.key_comp() == C(5));
50}
51{
52typedef std::pair<const int, double> V;
53const V ar[] =
54{
55V(1, 1),
56V(1, 1.5),
57V(1, 2),
58V(2, 1),
59V(2, 1.5),
60V(2, 2),
61V(3, 1),
62V(3, 1.5),
63V(3, 2),
64};
65std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
66std::multimap<int, double> *p = &m;
67m = *p;
68assert(m.size() == sizeof(ar)/sizeof(ar[0]));
69assert(std::equal(m.begin(), m.end(), ar));
70}
71{
72typedef std::pair<const int, double> V;
73V ar[] =
74{
75V(1, 1),
76V(1, 1.5),
77V(1, 2),
78V(2, 1),
79V(2, 1.5),
80V(2, 2),
81V(3, 1),
82V(3, 1.5),
83V(3, 2),
84};
85typedef test_less<int> C;
86typedef other_allocator<V> A;
87std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
88std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
89m = mo;
90assert(m == mo);
91assert(m.get_allocator() == A(2));
92assert(m.key_comp() == C(5));
93
94assert(mo.get_allocator() == A(2));
95assert(mo.key_comp() == C(5));
96}
97#if TEST_STD_VER >= 11
98{
99typedef std::pair<const int, double> V;
100V ar[] =
101{
102V(1, 1),
103V(1, 1.5),
104V(1, 2),
105V(2, 1),
106V(2, 1.5),
107V(2, 2),
108V(3, 1),
109V(3, 1.5),
110V(3, 2),
111};
112typedef test_less<int> C;
113typedef min_allocator<V> A;
114std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
115std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A());
116m = mo;
117assert(m == mo);
118assert(m.get_allocator() == A());
119assert(m.key_comp() == C(5));
120
121assert(mo.get_allocator() == A());
122assert(mo.key_comp() == C(5));
123}
124#endif
125
126return 0;
127}
128