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 "min_allocator.h"
20 
main()21 int main()
22 {
23     {
24     typedef std::pair<const int, double> V;
25     typedef std::map<int, double> M;
26     {
27         typedef M::size_type R;
28         V ar[] =
29         {
30             V(5, 5),
31             V(6, 6),
32             V(7, 7),
33             V(8, 8),
34             V(9, 9),
35             V(10, 10),
36             V(11, 11),
37             V(12, 12)
38         };
39         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
40         R r = m.count(5);
41         assert(r == 1);
42         r = m.count(6);
43         assert(r == 1);
44         r = m.count(7);
45         assert(r == 1);
46         r = m.count(8);
47         assert(r == 1);
48         r = m.count(9);
49         assert(r == 1);
50         r = m.count(10);
51         assert(r == 1);
52         r = m.count(11);
53         assert(r == 1);
54         r = m.count(12);
55         assert(r == 1);
56         r = m.count(4);
57         assert(r == 0);
58     }
59     }
60 #if __cplusplus >= 201103L
61     {
62     typedef std::pair<const int, double> V;
63     typedef std::map<int, double, std::less<int>, min_allocator<V>> M;
64     {
65         typedef M::size_type R;
66         V ar[] =
67         {
68             V(5, 5),
69             V(6, 6),
70             V(7, 7),
71             V(8, 8),
72             V(9, 9),
73             V(10, 10),
74             V(11, 11),
75             V(12, 12)
76         };
77         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
78         R r = m.count(5);
79         assert(r == 1);
80         r = m.count(6);
81         assert(r == 1);
82         r = m.count(7);
83         assert(r == 1);
84         r = m.count(8);
85         assert(r == 1);
86         r = m.count(9);
87         assert(r == 1);
88         r = m.count(10);
89         assert(r == 1);
90         r = m.count(11);
91         assert(r == 1);
92         r = m.count(12);
93         assert(r == 1);
94         r = m.count(4);
95         assert(r == 0);
96     }
97     }
98 #endif
99 }
100