xref: /llvm-project/libcxx/test/std/containers/associative/multiset/count.pass.cpp (revision cc89063bff0f73ec7049a1dcb5d4688ae6806941)
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 // size_type count(const key_type& k) const;
14 
15 #include <set>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "private_constructor.h"
21 
main(int,char **)22 int main(int, char**)
23 {
24     {
25     typedef int V;
26     typedef std::multiset<int> M;
27     {
28         typedef M::size_type R;
29         V ar[] =
30         {
31             5,
32             5,
33             5,
34             5,
35             7,
36             7,
37             7,
38             9,
39             9
40         };
41         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
42         R r = m.count(4);
43         assert(r == 0);
44         r = m.count(5);
45         assert(r == 4);
46         r = m.count(6);
47         assert(r == 0);
48         r = m.count(7);
49         assert(r == 3);
50         r = m.count(8);
51         assert(r == 0);
52         r = m.count(9);
53         assert(r == 2);
54         r = m.count(10);
55         assert(r == 0);
56     }
57     }
58 #if TEST_STD_VER >= 11
59     {
60     typedef int V;
61     typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
62     {
63         typedef M::size_type R;
64         V ar[] =
65         {
66             5,
67             5,
68             5,
69             5,
70             7,
71             7,
72             7,
73             9,
74             9
75         };
76         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
77         R r = m.count(4);
78         assert(r == 0);
79         r = m.count(5);
80         assert(r == 4);
81         r = m.count(6);
82         assert(r == 0);
83         r = m.count(7);
84         assert(r == 3);
85         r = m.count(8);
86         assert(r == 0);
87         r = m.count(9);
88         assert(r == 2);
89         r = m.count(10);
90         assert(r == 0);
91     }
92     }
93 #endif
94 #if TEST_STD_VER > 11
95     {
96     typedef int V;
97     typedef std::multiset<int, std::less<>> M;
98     typedef M::size_type R;
99     V ar[] =
100     {
101         5,
102         5,
103         5,
104         5,
105         7,
106         7,
107         7,
108         9,
109         9
110     };
111     const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
112     R r = m.count(4);
113     assert(r == 0);
114     r = m.count(5);
115     assert(r == 4);
116     r = m.count(6);
117     assert(r == 0);
118     r = m.count(7);
119     assert(r == 3);
120     r = m.count(8);
121     assert(r == 0);
122     r = m.count(9);
123     assert(r == 2);
124     r = m.count(10);
125     assert(r == 0);
126     }
127 
128     {
129     typedef PrivateConstructor V;
130     typedef std::multiset<V, std::less<>> M;
131     typedef M::size_type R;
132 
133     M m;
134     m.insert ( V::make ( 5 ));
135     m.insert ( V::make ( 5 ));
136     m.insert ( V::make ( 5 ));
137     m.insert ( V::make ( 5 ));
138     m.insert ( V::make ( 7 ));
139     m.insert ( V::make ( 7 ));
140     m.insert ( V::make ( 7 ));
141     m.insert ( V::make ( 9 ));
142     m.insert ( V::make ( 9 ));
143 
144     R r = m.count(4);
145     assert(r == 0);
146     r = m.count(5);
147     assert(r == 4);
148     r = m.count(6);
149     assert(r == 0);
150     r = m.count(7);
151     assert(r == 3);
152     r = m.count(8);
153     assert(r == 0);
154     r = m.count(9);
155     assert(r == 2);
156     r = m.count(10);
157     assert(r == 0);
158     }
159 #endif
160 
161   return 0;
162 }
163