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 // <map>
11
12 // class map
13
14 // size_type count(const key_type& k) const;
15
16 #include <map>
17 #include <cassert>
18
19 #include "test_macros.h"
20 #include "min_allocator.h"
21 #include "private_constructor.hpp"
22 #include "is_transparent.h"
23
main()24 int main()
25 {
26 {
27 typedef std::pair<const int, double> V;
28 typedef std::map<int, double> M;
29 {
30 typedef M::size_type R;
31 V ar[] =
32 {
33 V(5, 5),
34 V(6, 6),
35 V(7, 7),
36 V(8, 8),
37 V(9, 9),
38 V(10, 10),
39 V(11, 11),
40 V(12, 12)
41 };
42 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
43 R r = m.count(5);
44 assert(r == 1);
45 r = m.count(6);
46 assert(r == 1);
47 r = m.count(7);
48 assert(r == 1);
49 r = m.count(8);
50 assert(r == 1);
51 r = m.count(9);
52 assert(r == 1);
53 r = m.count(10);
54 assert(r == 1);
55 r = m.count(11);
56 assert(r == 1);
57 r = m.count(12);
58 assert(r == 1);
59 r = m.count(4);
60 assert(r == 0);
61 }
62 }
63 #if TEST_STD_VER >= 11
64 {
65 typedef std::pair<const int, double> V;
66 typedef std::map<int, double, std::less<int>, min_allocator<V>> M;
67 {
68 typedef M::size_type R;
69 V ar[] =
70 {
71 V(5, 5),
72 V(6, 6),
73 V(7, 7),
74 V(8, 8),
75 V(9, 9),
76 V(10, 10),
77 V(11, 11),
78 V(12, 12)
79 };
80 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
81 R r = m.count(5);
82 assert(r == 1);
83 r = m.count(6);
84 assert(r == 1);
85 r = m.count(7);
86 assert(r == 1);
87 r = m.count(8);
88 assert(r == 1);
89 r = m.count(9);
90 assert(r == 1);
91 r = m.count(10);
92 assert(r == 1);
93 r = m.count(11);
94 assert(r == 1);
95 r = m.count(12);
96 assert(r == 1);
97 r = m.count(4);
98 assert(r == 0);
99 }
100 }
101 #endif
102 #if TEST_STD_VER > 11
103 {
104 typedef std::pair<const int, double> V;
105 typedef std::map<int, double, std::less <>> M;
106 typedef M::size_type R;
107
108 V ar[] =
109 {
110 V(5, 5),
111 V(6, 6),
112 V(7, 7),
113 V(8, 8),
114 V(9, 9),
115 V(10, 10),
116 V(11, 11),
117 V(12, 12)
118 };
119 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
120 R r = m.count(5);
121 assert(r == 1);
122 r = m.count(6);
123 assert(r == 1);
124 r = m.count(7);
125 assert(r == 1);
126 r = m.count(8);
127 assert(r == 1);
128 r = m.count(9);
129 assert(r == 1);
130 r = m.count(10);
131 assert(r == 1);
132 r = m.count(11);
133 assert(r == 1);
134 r = m.count(12);
135 assert(r == 1);
136 r = m.count(4);
137 assert(r == 0);
138
139 r = m.count(C2Int(5));
140 assert(r == 1);
141 r = m.count(C2Int(6));
142 assert(r == 1);
143 r = m.count(C2Int(7));
144 assert(r == 1);
145 r = m.count(C2Int(8));
146 assert(r == 1);
147 r = m.count(C2Int(9));
148 assert(r == 1);
149 r = m.count(C2Int(10));
150 assert(r == 1);
151 r = m.count(C2Int(11));
152 assert(r == 1);
153 r = m.count(C2Int(12));
154 assert(r == 1);
155 r = m.count(C2Int(4));
156 assert(r == 0);
157 }
158
159 {
160 typedef PrivateConstructor PC;
161 typedef std::map<PC, double, std::less<>> M;
162 typedef M::size_type R;
163
164 M m;
165 m [ PC::make(5) ] = 5;
166 m [ PC::make(6) ] = 6;
167 m [ PC::make(7) ] = 7;
168 m [ PC::make(8) ] = 8;
169 m [ PC::make(9) ] = 9;
170 m [ PC::make(10) ] = 10;
171 m [ PC::make(11) ] = 11;
172 m [ PC::make(12) ] = 12;
173
174 R r = m.count(5);
175 assert(r == 1);
176 r = m.count(6);
177 assert(r == 1);
178 r = m.count(7);
179 assert(r == 1);
180 r = m.count(8);
181 assert(r == 1);
182 r = m.count(9);
183 assert(r == 1);
184 r = m.count(10);
185 assert(r == 1);
186 r = m.count(11);
187 assert(r == 1);
188 r = m.count(12);
189 assert(r == 1);
190 r = m.count(4);
191 assert(r == 0);
192 }
193 #endif
194 }
195