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 typedef std::pair<const int, double> V;
25 {
26 typedef std::multimap<int, double> M;
27 {
28 typedef M::size_type R;
29 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};
30 const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
31 R r = m.count(x: 4);
32 assert(r == 0);
33 r = m.count(x: 5);
34 assert(r == 3);
35 r = m.count(x: 6);
36 assert(r == 0);
37 r = m.count(x: 7);
38 assert(r == 3);
39 r = m.count(x: 8);
40 assert(r == 0);
41 r = m.count(x: 9);
42 assert(r == 3);
43 r = m.count(x: 10);
44 assert(r == 0);
45 }
46 }
47#if TEST_STD_VER >= 11
48 {
49 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
50 {
51 typedef M::size_type R;
52 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};
53 const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
54 R r = m.count(4);
55 assert(r == 0);
56 r = m.count(5);
57 assert(r == 3);
58 r = m.count(6);
59 assert(r == 0);
60 r = m.count(7);
61 assert(r == 3);
62 r = m.count(8);
63 assert(r == 0);
64 r = m.count(9);
65 assert(r == 3);
66 r = m.count(10);
67 assert(r == 0);
68 }
69 }
70#endif
71
72#if TEST_STD_VER > 11
73 {
74 typedef std::multimap<int, double, std::less<>> M;
75 typedef M::size_type R;
76 V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};
77 const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));
78 R r = m.count(4);
79 assert(r == 0);
80 r = m.count(5);
81 assert(r == 3);
82 r = m.count(6);
83 assert(r == 0);
84 r = m.count(7);
85 assert(r == 3);
86 r = m.count(8);
87 assert(r == 0);
88 r = m.count(9);
89 assert(r == 3);
90 r = m.count(10);
91 assert(r == 0);
92
93 r = m.count(C2Int(4));
94 assert(r == 0);
95 r = m.count(C2Int(5));
96 assert(r == 3);
97 r = m.count(C2Int(6));
98 assert(r == 0);
99 r = m.count(C2Int(7));
100 assert(r == 3);
101 r = m.count(C2Int(8));
102 assert(r == 0);
103 r = m.count(C2Int(9));
104 assert(r == 3);
105 r = m.count(C2Int(10));
106 assert(r == 0);
107 }
108
109 {
110 typedef PrivateConstructor PC;
111 typedef std::multimap<PC, double, std::less<>> M;
112 typedef M::size_type R;
113
114 M m;
115 m.insert(std::make_pair<PC, double>(PC::make(5), 1));
116 m.insert(std::make_pair<PC, double>(PC::make(5), 2));
117 m.insert(std::make_pair<PC, double>(PC::make(5), 3));
118 m.insert(std::make_pair<PC, double>(PC::make(7), 1));
119 m.insert(std::make_pair<PC, double>(PC::make(7), 2));
120 m.insert(std::make_pair<PC, double>(PC::make(7), 3));
121 m.insert(std::make_pair<PC, double>(PC::make(9), 1));
122 m.insert(std::make_pair<PC, double>(PC::make(9), 2));
123 m.insert(std::make_pair<PC, double>(PC::make(9), 3));
124
125 R r = m.count(4);
126 assert(r == 0);
127 r = m.count(5);
128 assert(r == 3);
129 r = m.count(6);
130 assert(r == 0);
131 r = m.count(7);
132 assert(r == 3);
133 r = m.count(8);
134 assert(r == 0);
135 r = m.count(9);
136 assert(r == 3);
137 r = m.count(10);
138 assert(r == 0);
139 }
140#endif
141
142 return 0;
143}
144

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