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 map
12
13// template <class InputIterator>
14// map(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::map<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() == 3);
45 assert(std::distance(m.begin(), m.end()) == 3);
46 assert(*m.begin() == V(1, 1));
47 assert(*std::next(m.begin()) == V(2, 1));
48 assert(*std::next(m.begin(), 2) == V(3, 1));
49 }
50#if TEST_STD_VER >= 11
51 {
52 typedef std::pair<const int, double> V;
53 V ar[] = {
54 V(1, 1),
55 V(1, 1.5),
56 V(1, 2),
57 V(2, 1),
58 V(2, 1.5),
59 V(2, 2),
60 V(3, 1),
61 V(3, 1.5),
62 V(3, 2),
63 };
64 typedef test_less<int> C;
65 typedef min_allocator<V> A;
66 std::map<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A());
67 assert(m.get_allocator() == A());
68 assert(m.key_comp() == C(5));
69 assert(m.size() == 3);
70 assert(std::distance(m.begin(), m.end()) == 3);
71 assert(*m.begin() == V(1, 1));
72 assert(*std::next(m.begin()) == V(2, 1));
73 assert(*std::next(m.begin(), 2) == V(3, 1));
74 }
75# if TEST_STD_VER > 11
76 {
77 typedef std::pair<const int, double> V;
78 V ar[] = {
79 V(1, 1),
80 V(1, 1.5),
81 V(1, 2),
82 V(2, 1),
83 V(2, 1.5),
84 V(2, 2),
85 V(3, 1),
86 V(3, 1.5),
87 V(3, 2),
88 };
89 {
90 typedef min_allocator<V> A;
91 typedef test_less<int> C;
92 A a;
93 std::map<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]), a);
94
95 assert(m.size() == 3);
96 assert(std::distance(m.begin(), m.end()) == 3);
97 assert(*m.begin() == V(1, 1));
98 assert(*std::next(m.begin()) == V(2, 1));
99 assert(*std::next(m.begin(), 2) == V(3, 1));
100 assert(m.get_allocator() == a);
101 }
102 {
103 typedef explicit_allocator<V> A;
104 typedef test_less<int> C;
105 A a;
106 std::map<int, double, C, A> m(ar, ar + sizeof(ar) / sizeof(ar[0]), a);
107
108 assert(m.size() == 3);
109 assert(std::distance(m.begin(), m.end()) == 3);
110 assert(*m.begin() == V(1, 1));
111 assert(*std::next(m.begin()) == V(2, 1));
112 assert(*std::next(m.begin(), 2) == V(3, 1));
113 assert(m.get_allocator() == a);
114 }
115 }
116# endif
117#endif
118
119 return 0;
120}
121

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