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

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