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 | // UNSUPPORTED: c++03 |
10 | |
11 | // <map> |
12 | |
13 | // class multimap |
14 | |
15 | // multimap(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); |
16 | |
17 | #include <map> |
18 | #include <cassert> |
19 | #include "test_macros.h" |
20 | #include "../../../test_compare.h" |
21 | #include "test_allocator.h" |
22 | #include "min_allocator.h" |
23 | |
24 | int main(int, char**) |
25 | { |
26 | { |
27 | typedef test_less<int> Cmp; |
28 | typedef test_allocator<std::pair<const int, double> > A; |
29 | typedef std::multimap<int, double, Cmp, A> C; |
30 | typedef C::value_type V; |
31 | C m( |
32 | { |
33 | {1, 1}, |
34 | {1, 1.5}, |
35 | {1, 2}, |
36 | {2, 1}, |
37 | {2, 1.5}, |
38 | {2, 2}, |
39 | {3, 1}, |
40 | {3, 1.5}, |
41 | {3, 2} |
42 | }, |
43 | Cmp(4), A(5) |
44 | ); |
45 | assert(m.size() == 9); |
46 | assert(std::distance(m.begin(), m.end()) == 9); |
47 | C::const_iterator i = m.cbegin(); |
48 | assert(*i == V(1, 1)); |
49 | assert(*++i == V(1, 1.5)); |
50 | assert(*++i == V(1, 2)); |
51 | assert(*++i == V(2, 1)); |
52 | assert(*++i == V(2, 1.5)); |
53 | assert(*++i == V(2, 2)); |
54 | assert(*++i == V(3, 1)); |
55 | assert(*++i == V(3, 1.5)); |
56 | assert(*++i == V(3, 2)); |
57 | assert(m.key_comp() == Cmp(4)); |
58 | assert(m.get_allocator() == A(5)); |
59 | } |
60 | { |
61 | typedef test_less<int> Cmp; |
62 | typedef min_allocator<std::pair<const int, double> > A; |
63 | typedef std::multimap<int, double, Cmp, A> C; |
64 | typedef C::value_type V; |
65 | C m( |
66 | { |
67 | {1, 1}, |
68 | {1, 1.5}, |
69 | {1, 2}, |
70 | {2, 1}, |
71 | {2, 1.5}, |
72 | {2, 2}, |
73 | {3, 1}, |
74 | {3, 1.5}, |
75 | {3, 2} |
76 | }, |
77 | Cmp(4), A() |
78 | ); |
79 | assert(m.size() == 9); |
80 | assert(std::distance(m.begin(), m.end()) == 9); |
81 | C::const_iterator i = m.cbegin(); |
82 | assert(*i == V(1, 1)); |
83 | assert(*++i == V(1, 1.5)); |
84 | assert(*++i == V(1, 2)); |
85 | assert(*++i == V(2, 1)); |
86 | assert(*++i == V(2, 1.5)); |
87 | assert(*++i == V(2, 2)); |
88 | assert(*++i == V(3, 1)); |
89 | assert(*++i == V(3, 1.5)); |
90 | assert(*++i == V(3, 2)); |
91 | assert(m.key_comp() == Cmp(4)); |
92 | assert(m.get_allocator() == A()); |
93 | } |
94 | { |
95 | typedef test_less<int> C; |
96 | typedef std::pair<const int, double> V; |
97 | typedef min_allocator<V> A; |
98 | typedef std::multimap<int, double, C, A> M; |
99 | A a; |
100 | M m ({ {1, 1}, |
101 | {1, 1.5}, |
102 | {1, 2}, |
103 | {2, 1}, |
104 | {2, 1.5}, |
105 | {2, 2}, |
106 | {3, 1}, |
107 | {3, 1.5}, |
108 | {3, 2} |
109 | }, a); |
110 | |
111 | assert(m.size() == 9); |
112 | assert(std::distance(m.begin(), m.end()) == 9); |
113 | M::const_iterator i = m.cbegin(); |
114 | assert(*i == V(1, 1)); |
115 | assert(*++i == V(1, 1.5)); |
116 | assert(*++i == V(1, 2)); |
117 | assert(*++i == V(2, 1)); |
118 | assert(*++i == V(2, 1.5)); |
119 | assert(*++i == V(2, 2)); |
120 | assert(*++i == V(3, 1)); |
121 | assert(*++i == V(3, 1.5)); |
122 | assert(*++i == V(3, 2)); |
123 | assert(m.get_allocator() == a); |
124 | } |
125 | { |
126 | typedef test_less<int> Cmp; |
127 | typedef explicit_allocator<std::pair<const int, double> > A; |
128 | typedef std::multimap<int, double, Cmp, A> C; |
129 | typedef C::value_type V; |
130 | C m( |
131 | { |
132 | {1, 1}, |
133 | {1, 1.5}, |
134 | {1, 2}, |
135 | {2, 1}, |
136 | {2, 1.5}, |
137 | {2, 2}, |
138 | {3, 1}, |
139 | {3, 1.5}, |
140 | {3, 2} |
141 | }, |
142 | Cmp(4), A{} |
143 | ); |
144 | assert(m.size() == 9); |
145 | assert(std::distance(m.begin(), m.end()) == 9); |
146 | C::const_iterator i = m.cbegin(); |
147 | assert(*i == V(1, 1)); |
148 | assert(*++i == V(1, 1.5)); |
149 | assert(*++i == V(1, 2)); |
150 | assert(*++i == V(2, 1)); |
151 | assert(*++i == V(2, 1.5)); |
152 | assert(*++i == V(2, 2)); |
153 | assert(*++i == V(3, 1)); |
154 | assert(*++i == V(3, 1.5)); |
155 | assert(*++i == V(3, 2)); |
156 | assert(m.key_comp() == Cmp(4)); |
157 | assert(m.get_allocator() == A{}); |
158 | } |
159 | |
160 | return 0; |
161 | } |
162 | |