xref: /llvm-project/libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp (revision 5ffe11a9fccfffbabbea5bbcc1cfd4b21af6d631)
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 
main(int,char **)25 int main(int, char**)
26 {
27     {
28     typedef std::pair<const int, double> V;
29     V ar[] =
30     {
31         V(1, 1),
32         V(1, 1.5),
33         V(1, 2),
34         V(2, 1),
35         V(2, 1.5),
36         V(2, 2),
37         V(3, 1),
38         V(3, 1.5),
39         V(3, 2),
40     };
41     typedef test_less<int> C;
42     typedef test_allocator<V> A;
43     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
44     assert(m.get_allocator() == A(7));
45     assert(m.key_comp() == C(5));
46     assert(m.size() == 3);
47     assert(std::distance(m.begin(), m.end()) == 3);
48     assert(*m.begin() == V(1, 1));
49     assert(*std::next(m.begin()) == V(2, 1));
50     assert(*std::next(m.begin(), 2) == V(3, 1));
51     }
52 #if TEST_STD_VER >= 11
53     {
54     typedef std::pair<const int, double> V;
55     V ar[] =
56     {
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     typedef min_allocator<V> A;
69     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
70     assert(m.get_allocator() == A());
71     assert(m.key_comp() == C(5));
72     assert(m.size() == 3);
73     assert(std::distance(m.begin(), m.end()) == 3);
74     assert(*m.begin() == V(1, 1));
75     assert(*std::next(m.begin()) == V(2, 1));
76     assert(*std::next(m.begin(), 2) == V(3, 1));
77     }
78 #if TEST_STD_VER > 11
79     {
80     typedef std::pair<const int, double> V;
81     V ar[] =
82     {
83         V(1, 1),
84         V(1, 1.5),
85         V(1, 2),
86         V(2, 1),
87         V(2, 1.5),
88         V(2, 2),
89         V(3, 1),
90         V(3, 1.5),
91         V(3, 2),
92     };
93     {
94     typedef min_allocator<V> A;
95     typedef test_less<int> C;
96     A a;
97     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a );
98 
99     assert(m.size() == 3);
100     assert(std::distance(m.begin(), m.end()) == 3);
101     assert(*m.begin() == V(1, 1));
102     assert(*std::next(m.begin()) == V(2, 1));
103     assert(*std::next(m.begin(), 2) == V(3, 1));
104     assert(m.get_allocator() == a);
105     }
106     {
107     typedef explicit_allocator<V> A;
108     typedef test_less<int> C;
109     A a;
110     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a );
111 
112     assert(m.size() == 3);
113     assert(std::distance(m.begin(), m.end()) == 3);
114     assert(*m.begin() == V(1, 1));
115     assert(*std::next(m.begin()) == V(2, 1));
116     assert(*std::next(m.begin(), 2) == V(3, 1));
117     assert(m.get_allocator() == a);
118     }
119     }
120 #endif
121 #endif
122 
123   return 0;
124 }
125