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