llvm-project
162 строки · 3.2 Кб
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
22int main(int, char**)
23{
24{
25typedef int V;
26typedef std::multiset<int> M;
27{
28typedef M::size_type R;
29V ar[] =
30{
315,
325,
335,
345,
357,
367,
377,
389,
399
40};
41const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
42R r = m.count(4);
43assert(r == 0);
44r = m.count(5);
45assert(r == 4);
46r = m.count(6);
47assert(r == 0);
48r = m.count(7);
49assert(r == 3);
50r = m.count(8);
51assert(r == 0);
52r = m.count(9);
53assert(r == 2);
54r = m.count(10);
55assert(r == 0);
56}
57}
58#if TEST_STD_VER >= 11
59{
60typedef int V;
61typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
62{
63typedef M::size_type R;
64V ar[] =
65{
665,
675,
685,
695,
707,
717,
727,
739,
749
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 == 4);
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 == 2);
89r = m.count(10);
90assert(r == 0);
91}
92}
93#endif
94#if TEST_STD_VER > 11
95{
96typedef int V;
97typedef std::multiset<int, std::less<>> M;
98typedef M::size_type R;
99V ar[] =
100{
1015,
1025,
1035,
1045,
1057,
1067,
1077,
1089,
1099
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 == 4);
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 == 2);
124r = m.count(10);
125assert(r == 0);
126}
127
128{
129typedef PrivateConstructor V;
130typedef std::multiset<V, std::less<>> M;
131typedef M::size_type R;
132
133M m;
134m.insert ( V::make ( 5 ));
135m.insert ( V::make ( 5 ));
136m.insert ( V::make ( 5 ));
137m.insert ( V::make ( 5 ));
138m.insert ( V::make ( 7 ));
139m.insert ( V::make ( 7 ));
140m.insert ( V::make ( 7 ));
141m.insert ( V::make ( 9 ));
142m.insert ( V::make ( 9 ));
143
144R r = m.count(4);
145assert(r == 0);
146r = m.count(5);
147assert(r == 4);
148r = m.count(6);
149assert(r == 0);
150r = m.count(7);
151assert(r == 3);
152r = m.count(8);
153assert(r == 0);
154r = m.count(9);
155assert(r == 2);
156r = m.count(10);
157assert(r == 0);
158}
159#endif
160
161return 0;
162}
163