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// <map>
10
11// class multimap
12
13// template <class InputIterator>
14// multimap(InputIterator first, InputIterator last,
15// const key_compare& comp, const allocator_type& a);
16
17#include <map>
18#include <cassert>
19
20#include "test_macros.h"
21#include "../../../test_compare.h"
22#include "test_allocator.h"
23#include "min_allocator.h"
24
25int main(int, char**) {
26 {
27 typedef std::pair<const int, double> V;
28 V ar[] = {
29 V(1, 1),
30 V(1, 1.5),
31 V(1, 2),
32 V(2, 1),
33 V(2, 1.5),
34 V(2, 2),
35 V(3, 1),
36 V(3, 1.5),
37 V(3, 2),
38 };
39 typedef test_less<int> C;
40 typedef test_allocator<V> A;
41 std::multimap<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(7));
42 assert(m.get_allocator() == A(7));
43 assert(m.key_comp() == C(5));
44 assert(m.size() == 9);
45 assert(std::distance(m.begin(), m.end()) == 9);
46 assert(*m.begin() == V(1, 1));
47 assert(*std::next(m.begin()) == V(1, 1.5));
48 assert(*std::next(m.begin(), 2) == V(1, 2));
49 assert(*std::next(m.begin(), 3) == V(2, 1));
50 assert(*std::next(m.begin(), 4) == V(2, 1.5));
51 assert(*std::next(m.begin(), 5) == V(2, 2));
52 assert(*std::next(m.begin(), 6) == V(3, 1));
53 assert(*std::next(m.begin(), 7) == V(3, 1.5));
54 assert(*std::next(m.begin(), 8) == V(3, 2));
55 }
56#if TEST_STD_VER >= 11
57 {
58 typedef std::pair<const int, double> V;
59 V ar[] = {
60 V(1, 1),
61 V(1, 1.5),
62 V(1, 2),
63 V(2, 1),
64 V(2, 1.5),
65 V(2, 2),
66 V(3, 1),
67 V(3, 1.5),
68 V(3, 2),
69 };
70 typedef test_less<int> C;
71 typedef min_allocator<V> A;
72 std::multimap<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A());
73 assert(m.get_allocator() == A());
74 assert(m.key_comp() == C(5));
75 assert(m.size() == 9);
76 assert(std::distance(m.begin(), m.end()) == 9);
77 assert(*m.begin() == V(1, 1));
78 assert(*std::next(m.begin()) == V(1, 1.5));
79 assert(*std::next(m.begin(), 2) == V(1, 2));
80 assert(*std::next(m.begin(), 3) == V(2, 1));
81 assert(*std::next(m.begin(), 4) == V(2, 1.5));
82 assert(*std::next(m.begin(), 5) == V(2, 2));
83 assert(*std::next(m.begin(), 6) == V(3, 1));
84 assert(*std::next(m.begin(), 7) == V(3, 1.5));
85 assert(*std::next(m.begin(), 8) == V(3, 2));
86 }
87 {
88 typedef std::pair<const int, double> V;
89 V ar[] = {
90 V(1, 1),
91 V(1, 1.5),
92 V(1, 2),
93 V(2, 1),
94 V(2, 1.5),
95 V(2, 2),
96 V(3, 1),
97 V(3, 1.5),
98 V(3, 2),
99 };
100 typedef test_less<int> C;
101 typedef explicit_allocator<V> A;
102 std::multimap<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A{});
103 assert(m.get_allocator() == A{});
104 assert(m.key_comp() == C(5));
105 assert(m.size() == 9);
106 assert(std::distance(m.begin(), m.end()) == 9);
107 assert(*m.begin() == V(1, 1));
108 assert(*std::next(m.begin()) == V(1, 1.5));
109 assert(*std::next(m.begin(), 2) == V(1, 2));
110 assert(*std::next(m.begin(), 3) == V(2, 1));
111 assert(*std::next(m.begin(), 4) == V(2, 1.5));
112 assert(*std::next(m.begin(), 5) == V(2, 2));
113 assert(*std::next(m.begin(), 6) == V(3, 1));
114 assert(*std::next(m.begin(), 7) == V(3, 1.5));
115 assert(*std::next(m.begin(), 8) == V(3, 2));
116 }
117#endif
118
119 return 0;
120}
121

source code of libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp