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 = key_compare()); |
16 | |
17 | #include <map> |
18 | #include <cassert> |
19 | #include "test_macros.h" |
20 | #include "../../../test_compare.h" |
21 | #include "min_allocator.h" |
22 | |
23 | int main(int, char**) |
24 | { |
25 | { |
26 | typedef test_less<int> Cmp; |
27 | typedef std::multimap<int, double, Cmp> C; |
28 | typedef C::value_type V; |
29 | C m( |
30 | { |
31 | {1, 1}, |
32 | {1, 1.5}, |
33 | {1, 2}, |
34 | {2, 1}, |
35 | {2, 1.5}, |
36 | {2, 2}, |
37 | {3, 1}, |
38 | {3, 1.5}, |
39 | {3, 2} |
40 | }, |
41 | Cmp(4) |
42 | ); |
43 | assert(m.size() == 9); |
44 | assert(std::distance(m.begin(), m.end()) == 9); |
45 | C::const_iterator i = m.cbegin(); |
46 | assert(*i == V(1, 1)); |
47 | assert(*++i == V(1, 1.5)); |
48 | assert(*++i == V(1, 2)); |
49 | assert(*++i == V(2, 1)); |
50 | assert(*++i == V(2, 1.5)); |
51 | assert(*++i == V(2, 2)); |
52 | assert(*++i == V(3, 1)); |
53 | assert(*++i == V(3, 1.5)); |
54 | assert(*++i == V(3, 2)); |
55 | assert(m.key_comp() == Cmp(4)); |
56 | } |
57 | { |
58 | typedef test_less<int> Cmp; |
59 | typedef std::multimap<int, double, Cmp, min_allocator<std::pair<const int, double>>> C; |
60 | typedef C::value_type V; |
61 | C m( |
62 | { |
63 | {1, 1}, |
64 | {1, 1.5}, |
65 | {1, 2}, |
66 | {2, 1}, |
67 | {2, 1.5}, |
68 | {2, 2}, |
69 | {3, 1}, |
70 | {3, 1.5}, |
71 | {3, 2} |
72 | }, |
73 | Cmp(4) |
74 | ); |
75 | assert(m.size() == 9); |
76 | assert(std::distance(m.begin(), m.end()) == 9); |
77 | C::const_iterator i = m.cbegin(); |
78 | assert(*i == V(1, 1)); |
79 | assert(*++i == V(1, 1.5)); |
80 | assert(*++i == V(1, 2)); |
81 | assert(*++i == V(2, 1)); |
82 | assert(*++i == V(2, 1.5)); |
83 | assert(*++i == V(2, 2)); |
84 | assert(*++i == V(3, 1)); |
85 | assert(*++i == V(3, 1.5)); |
86 | assert(*++i == V(3, 2)); |
87 | assert(m.key_comp() == Cmp(4)); |
88 | } |
89 | |
90 | return 0; |
91 | } |
92 | |