llvm-project
172 строки · 3.6 Кб
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 set
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::set<int> M;
27typedef M::size_type R;
28V ar[] =
29{
305,
316,
327,
338,
349,
3510,
3611,
3712
38};
39const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
40R r = m.count(5);
41assert(r == 1);
42r = m.count(6);
43assert(r == 1);
44r = m.count(7);
45assert(r == 1);
46r = m.count(8);
47assert(r == 1);
48r = m.count(9);
49assert(r == 1);
50r = m.count(10);
51assert(r == 1);
52r = m.count(11);
53assert(r == 1);
54r = m.count(12);
55assert(r == 1);
56r = m.count(4);
57assert(r == 0);
58}
59#if TEST_STD_VER >= 11
60{
61typedef int V;
62typedef std::set<int, std::less<int>, min_allocator<int>> M;
63typedef M::size_type R;
64V ar[] =
65{
665,
676,
687,
698,
709,
7110,
7211,
7312
74};
75const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
76R r = m.count(5);
77assert(r == 1);
78r = m.count(6);
79assert(r == 1);
80r = m.count(7);
81assert(r == 1);
82r = m.count(8);
83assert(r == 1);
84r = m.count(9);
85assert(r == 1);
86r = m.count(10);
87assert(r == 1);
88r = m.count(11);
89assert(r == 1);
90r = m.count(12);
91assert(r == 1);
92r = m.count(4);
93assert(r == 0);
94}
95#endif
96#if TEST_STD_VER > 11
97{
98typedef int V;
99typedef std::set<int, std::less<>> M;
100typedef M::size_type R;
101V ar[] =
102{
1035,
1046,
1057,
1068,
1079,
10810,
10911,
11012
111};
112const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
113R r = m.count(5);
114assert(r == 1);
115r = m.count(6);
116assert(r == 1);
117r = m.count(7);
118assert(r == 1);
119r = m.count(8);
120assert(r == 1);
121r = m.count(9);
122assert(r == 1);
123r = m.count(10);
124assert(r == 1);
125r = m.count(11);
126assert(r == 1);
127r = m.count(12);
128assert(r == 1);
129r = m.count(4);
130assert(r == 0);
131}
132{
133typedef PrivateConstructor V;
134typedef std::set<V, std::less<>> M;
135typedef M::size_type R;
136
137M m;
138m.insert ( V::make ( 5 ));
139m.insert ( V::make ( 6 ));
140m.insert ( V::make ( 7 ));
141m.insert ( V::make ( 8 ));
142m.insert ( V::make ( 9 ));
143m.insert ( V::make ( 10 ));
144m.insert ( V::make ( 11 ));
145m.insert ( V::make ( 12 ));
146
147const M& mc = m;
148
149R r = mc.count(5);
150assert(r == 1);
151r = mc.count(6);
152assert(r == 1);
153r = mc.count(7);
154assert(r == 1);
155r = mc.count(8);
156assert(r == 1);
157r = mc.count(9);
158assert(r == 1);
159r = mc.count(10);
160assert(r == 1);
161r = mc.count(11);
162assert(r == 1);
163r = mc.count(12);
164assert(r == 1);
165r = mc.count(4);
166assert(r == 0);
167}
168#endif
169
170
171return 0;
172}
173