• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <set>
11 
12 // class multiset
13 
14 // multiset& operator=(const multiset& s);
15 
16 #include <set>
17 #include <cassert>
18 
19 #include "../../../test_compare.h"
20 #include "test_allocator.h"
21 
main()22 int main()
23 {
24     {
25         typedef int V;
26         V ar[] =
27         {
28             1,
29             1,
30             1,
31             2,
32             2,
33             2,
34             3,
35             3,
36             3
37         };
38         typedef test_compare<std::less<int> > C;
39         typedef test_allocator<V> A;
40         std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
41         std::multiset<int, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
42         m = mo;
43         assert(m.get_allocator() == A(7));
44         assert(m.key_comp() == C(5));
45         assert(m.size() == 9);
46         assert(distance(m.begin(), m.end()) == 9);
47         assert(*next(m.begin(), 0) == 1);
48         assert(*next(m.begin(), 1) == 1);
49         assert(*next(m.begin(), 2) == 1);
50         assert(*next(m.begin(), 3) == 2);
51         assert(*next(m.begin(), 4) == 2);
52         assert(*next(m.begin(), 5) == 2);
53         assert(*next(m.begin(), 6) == 3);
54         assert(*next(m.begin(), 7) == 3);
55         assert(*next(m.begin(), 8) == 3);
56 
57         assert(mo.get_allocator() == A(2));
58         assert(mo.key_comp() == C(5));
59         assert(mo.size() == 9);
60         assert(distance(mo.begin(), mo.end()) == 9);
61         assert(*next(mo.begin(), 0) == 1);
62         assert(*next(mo.begin(), 1) == 1);
63         assert(*next(mo.begin(), 2) == 1);
64         assert(*next(mo.begin(), 3) == 2);
65         assert(*next(mo.begin(), 4) == 2);
66         assert(*next(mo.begin(), 5) == 2);
67         assert(*next(mo.begin(), 6) == 3);
68         assert(*next(mo.begin(), 7) == 3);
69         assert(*next(mo.begin(), 8) == 3);
70     }
71     {
72         typedef int V;
73         const V ar[] =
74         {
75             1,
76             1,
77             1,
78             2,
79             2,
80             2,
81             3,
82             3,
83             3
84         };
85         std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
86         std::multiset<int> *p = &m;
87         m = *p;
88         assert(m.size() == 9);
89         assert(std::equal(m.begin(), m.end(), ar));
90     }
91     {
92         typedef int V;
93         V ar[] =
94         {
95             1,
96             1,
97             1,
98             2,
99             2,
100             2,
101             3,
102             3,
103             3
104         };
105         typedef test_compare<std::less<int> > C;
106         typedef other_allocator<V> A;
107         std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2));
108         std::multiset<int, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7));
109         m = mo;
110         assert(m.get_allocator() == A(2));
111         assert(m.key_comp() == C(5));
112         assert(m.size() == 9);
113         assert(distance(m.begin(), m.end()) == 9);
114         assert(*next(m.begin(), 0) == 1);
115         assert(*next(m.begin(), 1) == 1);
116         assert(*next(m.begin(), 2) == 1);
117         assert(*next(m.begin(), 3) == 2);
118         assert(*next(m.begin(), 4) == 2);
119         assert(*next(m.begin(), 5) == 2);
120         assert(*next(m.begin(), 6) == 3);
121         assert(*next(m.begin(), 7) == 3);
122         assert(*next(m.begin(), 8) == 3);
123 
124         assert(mo.get_allocator() == A(2));
125         assert(mo.key_comp() == C(5));
126         assert(mo.size() == 9);
127         assert(distance(mo.begin(), mo.end()) == 9);
128         assert(*next(mo.begin(), 0) == 1);
129         assert(*next(mo.begin(), 1) == 1);
130         assert(*next(mo.begin(), 2) == 1);
131         assert(*next(mo.begin(), 3) == 2);
132         assert(*next(mo.begin(), 4) == 2);
133         assert(*next(mo.begin(), 5) == 2);
134         assert(*next(mo.begin(), 6) == 3);
135         assert(*next(mo.begin(), 7) == 3);
136         assert(*next(mo.begin(), 8) == 3);
137     }
138 }
139