llvm-project
120 строк · 3.7 Кб
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(const multiset& m);
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(7));
41std::multiset<int, C, A> m = mo;
42assert(m.get_allocator() == A(7));
43assert(m.key_comp() == C(5));
44assert(m.size() == 9);
45assert(std::distance(m.begin(), m.end()) == 9);
46assert(*std::next(m.begin(), 0) == 1);
47assert(*std::next(m.begin(), 1) == 1);
48assert(*std::next(m.begin(), 2) == 1);
49assert(*std::next(m.begin(), 3) == 2);
50assert(*std::next(m.begin(), 4) == 2);
51assert(*std::next(m.begin(), 5) == 2);
52assert(*std::next(m.begin(), 6) == 3);
53assert(*std::next(m.begin(), 7) == 3);
54assert(*std::next(m.begin(), 8) == 3);
55
56assert(mo.get_allocator() == A(7));
57assert(mo.key_comp() == C(5));
58assert(mo.size() == 9);
59assert(std::distance(mo.begin(), mo.end()) == 9);
60assert(*std::next(mo.begin(), 0) == 1);
61assert(*std::next(mo.begin(), 1) == 1);
62assert(*std::next(mo.begin(), 2) == 1);
63assert(*std::next(mo.begin(), 3) == 2);
64assert(*std::next(mo.begin(), 4) == 2);
65assert(*std::next(mo.begin(), 5) == 2);
66assert(*std::next(mo.begin(), 6) == 3);
67assert(*std::next(mo.begin(), 7) == 3);
68assert(*std::next(mo.begin(), 8) == 3);
69}
70#if TEST_STD_VER >= 11
71{
72typedef int V;
73V ar[] =
74{
751,
761,
771,
782,
792,
802,
813,
823,
833
84};
85typedef test_less<int> C;
86typedef other_allocator<V> A;
87std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
88std::multiset<int, C, A> m = mo;
89assert(m.get_allocator() == A(-2));
90assert(m.key_comp() == C(5));
91assert(m.size() == 9);
92assert(std::distance(m.begin(), m.end()) == 9);
93assert(*std::next(m.begin(), 0) == 1);
94assert(*std::next(m.begin(), 1) == 1);
95assert(*std::next(m.begin(), 2) == 1);
96assert(*std::next(m.begin(), 3) == 2);
97assert(*std::next(m.begin(), 4) == 2);
98assert(*std::next(m.begin(), 5) == 2);
99assert(*std::next(m.begin(), 6) == 3);
100assert(*std::next(m.begin(), 7) == 3);
101assert(*std::next(m.begin(), 8) == 3);
102
103assert(mo.get_allocator() == A(7));
104assert(mo.key_comp() == C(5));
105assert(mo.size() == 9);
106assert(std::distance(mo.begin(), mo.end()) == 9);
107assert(*std::next(mo.begin(), 0) == 1);
108assert(*std::next(mo.begin(), 1) == 1);
109assert(*std::next(mo.begin(), 2) == 1);
110assert(*std::next(mo.begin(), 3) == 2);
111assert(*std::next(mo.begin(), 4) == 2);
112assert(*std::next(mo.begin(), 5) == 2);
113assert(*std::next(mo.begin(), 6) == 3);
114assert(*std::next(mo.begin(), 7) == 3);
115assert(*std::next(mo.begin(), 8) == 3);
116}
117#endif
118
119return 0;
120}
121