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 | // void insert(InputIterator first, InputIterator last); |
15 | |
16 | #include <map> |
17 | #include <cassert> |
18 | |
19 | #include "test_macros.h" |
20 | #include "test_iterators.h" |
21 | #include "min_allocator.h" |
22 | |
23 | int main(int, char**) { |
24 | { |
25 | typedef std::multimap<int, double> M; |
26 | typedef std::pair<int, double> P; |
27 | P ar[] = { |
28 | P(1, 1), |
29 | P(1, 1.5), |
30 | P(1, 2), |
31 | P(2, 1), |
32 | P(2, 1.5), |
33 | P(2, 2), |
34 | P(3, 1), |
35 | P(3, 1.5), |
36 | P(3, 2), |
37 | }; |
38 | M m; |
39 | m.insert(cpp17_input_iterator<P*>(ar), cpp17_input_iterator<P*>(ar + sizeof(ar) / sizeof(ar[0]))); |
40 | assert(m.size() == 9); |
41 | assert(m.begin()->first == 1); |
42 | assert(m.begin()->second == 1); |
43 | assert(std::next(m.begin())->first == 1); |
44 | assert(std::next(m.begin())->second == 1.5); |
45 | assert(std::next(m.begin(), 2)->first == 1); |
46 | assert(std::next(m.begin(), 2)->second == 2); |
47 | assert(std::next(m.begin(), 3)->first == 2); |
48 | assert(std::next(m.begin(), 3)->second == 1); |
49 | assert(std::next(m.begin(), 4)->first == 2); |
50 | assert(std::next(m.begin(), 4)->second == 1.5); |
51 | assert(std::next(m.begin(), 5)->first == 2); |
52 | assert(std::next(m.begin(), 5)->second == 2); |
53 | assert(std::next(m.begin(), 6)->first == 3); |
54 | assert(std::next(m.begin(), 6)->second == 1); |
55 | assert(std::next(m.begin(), 7)->first == 3); |
56 | assert(std::next(m.begin(), 7)->second == 1.5); |
57 | assert(std::next(m.begin(), 8)->first == 3); |
58 | assert(std::next(m.begin(), 8)->second == 2); |
59 | } |
60 | #if TEST_STD_VER >= 11 |
61 | { |
62 | typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; |
63 | typedef std::pair<int, double> P; |
64 | P ar[] = { |
65 | P(1, 1), |
66 | P(1, 1.5), |
67 | P(1, 2), |
68 | P(2, 1), |
69 | P(2, 1.5), |
70 | P(2, 2), |
71 | P(3, 1), |
72 | P(3, 1.5), |
73 | P(3, 2), |
74 | }; |
75 | M m; |
76 | m.insert(cpp17_input_iterator<P*>(ar), cpp17_input_iterator<P*>(ar + sizeof(ar) / sizeof(ar[0]))); |
77 | assert(m.size() == 9); |
78 | assert(m.begin()->first == 1); |
79 | assert(m.begin()->second == 1); |
80 | assert(std::next(m.begin())->first == 1); |
81 | assert(std::next(m.begin())->second == 1.5); |
82 | assert(std::next(m.begin(), 2)->first == 1); |
83 | assert(std::next(m.begin(), 2)->second == 2); |
84 | assert(std::next(m.begin(), 3)->first == 2); |
85 | assert(std::next(m.begin(), 3)->second == 1); |
86 | assert(std::next(m.begin(), 4)->first == 2); |
87 | assert(std::next(m.begin(), 4)->second == 1.5); |
88 | assert(std::next(m.begin(), 5)->first == 2); |
89 | assert(std::next(m.begin(), 5)->second == 2); |
90 | assert(std::next(m.begin(), 6)->first == 3); |
91 | assert(std::next(m.begin(), 6)->second == 1); |
92 | assert(std::next(m.begin(), 7)->first == 3); |
93 | assert(std::next(m.begin(), 7)->second == 1.5); |
94 | assert(std::next(m.begin(), 8)->first == 3); |
95 | assert(std::next(m.begin(), 8)->second == 2); |
96 | } |
97 | #endif |
98 | |
99 | return 0; |
100 | } |
101 | |