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// <map>
10
11// class multimap
12
13// size_type count(const key_type& k) const;
14
15#include <map>
16#include <cassert>
17
18#include "test_macros.h"
19#include "min_allocator.h"
20#include "private_constructor.h"
21#include "is_transparent.h"
22
23int main(int, char**)
24{
25 typedef std::pair<const int, double> V;
26 {
27 typedef std::multimap<int, double> M;
28 {
29 typedef M::size_type R;
30 V ar[] =
31 {
32 V(5, 1),
33 V(5, 2),
34 V(5, 3),
35 V(7, 1),
36 V(7, 2),
37 V(7, 3),
38 V(9, 1),
39 V(9, 2),
40 V(9, 3)
41 };
42 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
43 R r = m.count(x: 4);
44 assert(r == 0);
45 r = m.count(x: 5);
46 assert(r == 3);
47 r = m.count(x: 6);
48 assert(r == 0);
49 r = m.count(x: 7);
50 assert(r == 3);
51 r = m.count(x: 8);
52 assert(r == 0);
53 r = m.count(x: 9);
54 assert(r == 3);
55 r = m.count(x: 10);
56 assert(r == 0);
57 }
58 }
59#if TEST_STD_VER >= 11
60 {
61 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
62 {
63 typedef M::size_type R;
64 V ar[] =
65 {
66 V(5, 1),
67 V(5, 2),
68 V(5, 3),
69 V(7, 1),
70 V(7, 2),
71 V(7, 3),
72 V(9, 1),
73 V(9, 2),
74 V(9, 3)
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 == 3);
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 == 3);
89 r = m.count(10);
90 assert(r == 0);
91 }
92 }
93#endif
94
95#if TEST_STD_VER > 11
96 {
97 typedef std::multimap<int, double, std::less<>> M;
98 typedef M::size_type R;
99 V ar[] =
100 {
101 V(5, 1),
102 V(5, 2),
103 V(5, 3),
104 V(7, 1),
105 V(7, 2),
106 V(7, 3),
107 V(9, 1),
108 V(9, 2),
109 V(9, 3)
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 == 3);
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 == 3);
124 r = m.count(10);
125 assert(r == 0);
126
127 r = m.count(C2Int(4));
128 assert(r == 0);
129 r = m.count(C2Int(5));
130 assert(r == 3);
131 r = m.count(C2Int(6));
132 assert(r == 0);
133 r = m.count(C2Int(7));
134 assert(r == 3);
135 r = m.count(C2Int(8));
136 assert(r == 0);
137 r = m.count(C2Int(9));
138 assert(r == 3);
139 r = m.count(C2Int(10));
140 assert(r == 0);
141 }
142
143 {
144 typedef PrivateConstructor PC;
145 typedef std::multimap<PC, double, std::less<>> M;
146 typedef M::size_type R;
147
148 M m;
149 m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
150 m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
151 m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
152 m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
153 m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
154 m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
155 m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
156 m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
157 m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
158
159 R r = m.count(4);
160 assert(r == 0);
161 r = m.count(5);
162 assert(r == 3);
163 r = m.count(6);
164 assert(r == 0);
165 r = m.count(7);
166 assert(r == 3);
167 r = m.count(8);
168 assert(r == 0);
169 r = m.count(9);
170 assert(r == 3);
171 r = m.count(10);
172 assert(r == 0);
173 }
174#endif
175
176 return 0;
177}
178

source code of libcxx/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp