1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <set>
11
12 // class set
13
14 // size_type count(const key_type& k) const;
15
16 #include <set>
17 #include <cassert>
18
19 #include "test_macros.h"
20 #include "min_allocator.h"
21 #include "private_constructor.hpp"
22
main()23 int main()
24 {
25 {
26 typedef int V;
27 typedef std::set<int> M;
28 typedef M::size_type R;
29 V ar[] =
30 {
31 5,
32 6,
33 7,
34 8,
35 9,
36 10,
37 11,
38 12
39 };
40 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
41 R r = m.count(5);
42 assert(r == 1);
43 r = m.count(6);
44 assert(r == 1);
45 r = m.count(7);
46 assert(r == 1);
47 r = m.count(8);
48 assert(r == 1);
49 r = m.count(9);
50 assert(r == 1);
51 r = m.count(10);
52 assert(r == 1);
53 r = m.count(11);
54 assert(r == 1);
55 r = m.count(12);
56 assert(r == 1);
57 r = m.count(4);
58 assert(r == 0);
59 }
60 #if TEST_STD_VER >= 11
61 {
62 typedef int V;
63 typedef std::set<int, std::less<int>, min_allocator<int>> M;
64 typedef M::size_type R;
65 V ar[] =
66 {
67 5,
68 6,
69 7,
70 8,
71 9,
72 10,
73 11,
74 12
75 };
76 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
77 R r = m.count(5);
78 assert(r == 1);
79 r = m.count(6);
80 assert(r == 1);
81 r = m.count(7);
82 assert(r == 1);
83 r = m.count(8);
84 assert(r == 1);
85 r = m.count(9);
86 assert(r == 1);
87 r = m.count(10);
88 assert(r == 1);
89 r = m.count(11);
90 assert(r == 1);
91 r = m.count(12);
92 assert(r == 1);
93 r = m.count(4);
94 assert(r == 0);
95 }
96 #endif
97 #if TEST_STD_VER > 11
98 {
99 typedef int V;
100 typedef std::set<int, std::less<>> M;
101 typedef M::size_type R;
102 V ar[] =
103 {
104 5,
105 6,
106 7,
107 8,
108 9,
109 10,
110 11,
111 12
112 };
113 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
114 R r = m.count(5);
115 assert(r == 1);
116 r = m.count(6);
117 assert(r == 1);
118 r = m.count(7);
119 assert(r == 1);
120 r = m.count(8);
121 assert(r == 1);
122 r = m.count(9);
123 assert(r == 1);
124 r = m.count(10);
125 assert(r == 1);
126 r = m.count(11);
127 assert(r == 1);
128 r = m.count(12);
129 assert(r == 1);
130 r = m.count(4);
131 assert(r == 0);
132 }
133 {
134 typedef PrivateConstructor V;
135 typedef std::set<V, std::less<>> M;
136 typedef M::size_type R;
137
138 M m;
139 m.insert ( V::make ( 5 ));
140 m.insert ( V::make ( 6 ));
141 m.insert ( V::make ( 7 ));
142 m.insert ( V::make ( 8 ));
143 m.insert ( V::make ( 9 ));
144 m.insert ( V::make ( 10 ));
145 m.insert ( V::make ( 11 ));
146 m.insert ( V::make ( 12 ));
147
148 const M& mc = m;
149
150 R r = mc.count(5);
151 assert(r == 1);
152 r = mc.count(6);
153 assert(r == 1);
154 r = mc.count(7);
155 assert(r == 1);
156 r = mc.count(8);
157 assert(r == 1);
158 r = mc.count(9);
159 assert(r == 1);
160 r = mc.count(10);
161 assert(r == 1);
162 r = mc.count(11);
163 assert(r == 1);
164 r = mc.count(12);
165 assert(r == 1);
166 r = mc.count(4);
167 assert(r == 0);
168 }
169 #endif
170
171 }
172