llvm-project
177 строк · 4.1 Кб
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{
25typedef std::pair<const int, double> V;
26{
27typedef std::multimap<int, double> M;
28{
29typedef M::size_type R;
30V ar[] =
31{
32V(5, 1),
33V(5, 2),
34V(5, 3),
35V(7, 1),
36V(7, 2),
37V(7, 3),
38V(9, 1),
39V(9, 2),
40V(9, 3)
41};
42const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
43R r = m.count(4);
44assert(r == 0);
45r = m.count(5);
46assert(r == 3);
47r = m.count(6);
48assert(r == 0);
49r = m.count(7);
50assert(r == 3);
51r = m.count(8);
52assert(r == 0);
53r = m.count(9);
54assert(r == 3);
55r = m.count(10);
56assert(r == 0);
57}
58}
59#if TEST_STD_VER >= 11
60{
61typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
62{
63typedef M::size_type R;
64V ar[] =
65{
66V(5, 1),
67V(5, 2),
68V(5, 3),
69V(7, 1),
70V(7, 2),
71V(7, 3),
72V(9, 1),
73V(9, 2),
74V(9, 3)
75};
76const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
77R r = m.count(4);
78assert(r == 0);
79r = m.count(5);
80assert(r == 3);
81r = m.count(6);
82assert(r == 0);
83r = m.count(7);
84assert(r == 3);
85r = m.count(8);
86assert(r == 0);
87r = m.count(9);
88assert(r == 3);
89r = m.count(10);
90assert(r == 0);
91}
92}
93#endif
94
95#if TEST_STD_VER > 11
96{
97typedef std::multimap<int, double, std::less<>> M;
98typedef M::size_type R;
99V ar[] =
100{
101V(5, 1),
102V(5, 2),
103V(5, 3),
104V(7, 1),
105V(7, 2),
106V(7, 3),
107V(9, 1),
108V(9, 2),
109V(9, 3)
110};
111const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
112R r = m.count(4);
113assert(r == 0);
114r = m.count(5);
115assert(r == 3);
116r = m.count(6);
117assert(r == 0);
118r = m.count(7);
119assert(r == 3);
120r = m.count(8);
121assert(r == 0);
122r = m.count(9);
123assert(r == 3);
124r = m.count(10);
125assert(r == 0);
126
127r = m.count(C2Int(4));
128assert(r == 0);
129r = m.count(C2Int(5));
130assert(r == 3);
131r = m.count(C2Int(6));
132assert(r == 0);
133r = m.count(C2Int(7));
134assert(r == 3);
135r = m.count(C2Int(8));
136assert(r == 0);
137r = m.count(C2Int(9));
138assert(r == 3);
139r = m.count(C2Int(10));
140assert(r == 0);
141}
142
143{
144typedef PrivateConstructor PC;
145typedef std::multimap<PC, double, std::less<>> M;
146typedef M::size_type R;
147
148M m;
149m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
150m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
151m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
152m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
153m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
154m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
155m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
156m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
157m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
158
159R r = m.count(4);
160assert(r == 0);
161r = m.count(5);
162assert(r == 3);
163r = m.count(6);
164assert(r == 0);
165r = m.count(7);
166assert(r == 3);
167r = m.count(8);
168assert(r == 0);
169r = m.count(9);
170assert(r == 3);
171r = m.count(10);
172assert(r == 0);
173}
174#endif
175
176return 0;
177}
178