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#include <iterator>
18
19#include "test_macros.h"
20#include "../../../test_compare.h"
21#include "test_allocator.h"
22
23int main(int, char**) {
24 {
25 typedef int V;
26 V ar[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};
27 typedef test_less<int> C;
28 typedef test_allocator<V> A;
29 std::multiset<int, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(2));
30 std::multiset<int, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]) / 2, C(3), A(7));
31 m = mo;
32 assert(m.get_allocator() == A(7));
33 assert(m.key_comp() == C(5));
34 assert(m.size() == 9);
35 assert(std::distance(m.begin(), m.end()) == 9);
36 assert(*std::next(m.begin(), 0) == 1);
37 assert(*std::next(m.begin(), 1) == 1);
38 assert(*std::next(m.begin(), 2) == 1);
39 assert(*std::next(m.begin(), 3) == 2);
40 assert(*std::next(m.begin(), 4) == 2);
41 assert(*std::next(m.begin(), 5) == 2);
42 assert(*std::next(m.begin(), 6) == 3);
43 assert(*std::next(m.begin(), 7) == 3);
44 assert(*std::next(m.begin(), 8) == 3);
45
46 assert(mo.get_allocator() == A(2));
47 assert(mo.key_comp() == C(5));
48 assert(mo.size() == 9);
49 assert(std::distance(mo.begin(), mo.end()) == 9);
50 assert(*std::next(mo.begin(), 0) == 1);
51 assert(*std::next(mo.begin(), 1) == 1);
52 assert(*std::next(mo.begin(), 2) == 1);
53 assert(*std::next(mo.begin(), 3) == 2);
54 assert(*std::next(mo.begin(), 4) == 2);
55 assert(*std::next(mo.begin(), 5) == 2);
56 assert(*std::next(mo.begin(), 6) == 3);
57 assert(*std::next(mo.begin(), 7) == 3);
58 assert(*std::next(mo.begin(), 8) == 3);
59 }
60 {
61 typedef int V;
62 const V ar[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};
63 std::multiset<int> m(ar, ar + sizeof(ar) / sizeof(ar[0]));
64 std::multiset<int>* p = &m;
65 m = *p;
66 assert(m.size() == 9);
67 assert(std::equal(m.begin(), m.end(), ar));
68 }
69 {
70 typedef int V;
71 V ar[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};
72 typedef test_less<int> C;
73 typedef other_allocator<V> A;
74 std::multiset<int, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(2));
75 std::multiset<int, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]) / 2, C(3), A(7));
76 m = mo;
77 assert(m.get_allocator() == A(2));
78 assert(m.key_comp() == C(5));
79 assert(m.size() == 9);
80 assert(std::distance(m.begin(), m.end()) == 9);
81 assert(*std::next(m.begin(), 0) == 1);
82 assert(*std::next(m.begin(), 1) == 1);
83 assert(*std::next(m.begin(), 2) == 1);
84 assert(*std::next(m.begin(), 3) == 2);
85 assert(*std::next(m.begin(), 4) == 2);
86 assert(*std::next(m.begin(), 5) == 2);
87 assert(*std::next(m.begin(), 6) == 3);
88 assert(*std::next(m.begin(), 7) == 3);
89 assert(*std::next(m.begin(), 8) == 3);
90
91 assert(mo.get_allocator() == A(2));
92 assert(mo.key_comp() == C(5));
93 assert(mo.size() == 9);
94 assert(std::distance(mo.begin(), mo.end()) == 9);
95 assert(*std::next(mo.begin(), 0) == 1);
96 assert(*std::next(mo.begin(), 1) == 1);
97 assert(*std::next(mo.begin(), 2) == 1);
98 assert(*std::next(mo.begin(), 3) == 2);
99 assert(*std::next(mo.begin(), 4) == 2);
100 assert(*std::next(mo.begin(), 5) == 2);
101 assert(*std::next(mo.begin(), 6) == 3);
102 assert(*std::next(mo.begin(), 7) == 3);
103 assert(*std::next(mo.begin(), 8) == 3);
104 }
105
106 return 0;
107}
108

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