llvm-project
140 строк · 4.2 Кб
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// <set>
10
11// class multiset
12
13// multiset& operator=(const multiset& s);
14
15#include <set>
16#include <cassert>
17
18#include "test_macros.h"
19#include "../../../test_compare.h"
20#include "test_allocator.h"
21
22int main(int, char**)
23{
24{
25typedef int V;
26V ar[] =
27{
281,
291,
301,
312,
322,
332,
343,
353,
363
37};
38typedef test_less<int> C;
39typedef test_allocator<V> A;
40std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
41std::multiset<int, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
42m = mo;
43assert(m.get_allocator() == A(7));
44assert(m.key_comp() == C(5));
45assert(m.size() == 9);
46assert(std::distance(m.begin(), m.end()) == 9);
47assert(*std::next(m.begin(), 0) == 1);
48assert(*std::next(m.begin(), 1) == 1);
49assert(*std::next(m.begin(), 2) == 1);
50assert(*std::next(m.begin(), 3) == 2);
51assert(*std::next(m.begin(), 4) == 2);
52assert(*std::next(m.begin(), 5) == 2);
53assert(*std::next(m.begin(), 6) == 3);
54assert(*std::next(m.begin(), 7) == 3);
55assert(*std::next(m.begin(), 8) == 3);
56
57assert(mo.get_allocator() == A(2));
58assert(mo.key_comp() == C(5));
59assert(mo.size() == 9);
60assert(std::distance(mo.begin(), mo.end()) == 9);
61assert(*std::next(mo.begin(), 0) == 1);
62assert(*std::next(mo.begin(), 1) == 1);
63assert(*std::next(mo.begin(), 2) == 1);
64assert(*std::next(mo.begin(), 3) == 2);
65assert(*std::next(mo.begin(), 4) == 2);
66assert(*std::next(mo.begin(), 5) == 2);
67assert(*std::next(mo.begin(), 6) == 3);
68assert(*std::next(mo.begin(), 7) == 3);
69assert(*std::next(mo.begin(), 8) == 3);
70}
71{
72typedef int V;
73const V ar[] =
74{
751,
761,
771,
782,
792,
802,
813,
823,
833
84};
85std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
86std::multiset<int> *p = &m;
87m = *p;
88assert(m.size() == 9);
89assert(std::equal(m.begin(), m.end(), ar));
90}
91{
92typedef int V;
93V ar[] =
94{
951,
961,
971,
982,
992,
1002,
1013,
1023,
1033
104};
105typedef test_less<int> C;
106typedef other_allocator<V> A;
107std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
108std::multiset<int, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
109m = mo;
110assert(m.get_allocator() == A(2));
111assert(m.key_comp() == C(5));
112assert(m.size() == 9);
113assert(std::distance(m.begin(), m.end()) == 9);
114assert(*std::next(m.begin(), 0) == 1);
115assert(*std::next(m.begin(), 1) == 1);
116assert(*std::next(m.begin(), 2) == 1);
117assert(*std::next(m.begin(), 3) == 2);
118assert(*std::next(m.begin(), 4) == 2);
119assert(*std::next(m.begin(), 5) == 2);
120assert(*std::next(m.begin(), 6) == 3);
121assert(*std::next(m.begin(), 7) == 3);
122assert(*std::next(m.begin(), 8) == 3);
123
124assert(mo.get_allocator() == A(2));
125assert(mo.key_comp() == C(5));
126assert(mo.size() == 9);
127assert(std::distance(mo.begin(), mo.end()) == 9);
128assert(*std::next(mo.begin(), 0) == 1);
129assert(*std::next(mo.begin(), 1) == 1);
130assert(*std::next(mo.begin(), 2) == 1);
131assert(*std::next(mo.begin(), 3) == 2);
132assert(*std::next(mo.begin(), 4) == 2);
133assert(*std::next(mo.begin(), 5) == 2);
134assert(*std::next(mo.begin(), 6) == 3);
135assert(*std::next(mo.begin(), 7) == 3);
136assert(*std::next(mo.begin(), 8) == 3);
137}
138
139return 0;
140}
141