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

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