1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <map>
11 
12 // class map
13 
14 // template <class InputIterator>
15 //     map(InputIterator first, InputIterator last,
16 //         const key_compare& comp, const allocator_type& a);
17 
18 #include <map>
19 #include <cassert>
20 
21 #include "../../../test_compare.h"
22 #include "test_allocator.h"
23 #include "min_allocator.h"
24 
main()25 int main()
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_compare<std::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(distance(m.begin(), m.end()) == 3);
48     assert(*m.begin() == V(1, 1));
49     assert(*next(m.begin()) == V(2, 1));
50     assert(*next(m.begin(), 2) == V(3, 1));
51     }
52 #if __cplusplus >= 201103L
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_compare<std::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(distance(m.begin(), m.end()) == 3);
74     assert(*m.begin() == V(1, 1));
75     assert(*next(m.begin()) == V(2, 1));
76     assert(*next(m.begin(), 2) == V(3, 1));
77     }
78 #if _LIBCPP_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     typedef std::pair<const int, double> V;
94     typedef min_allocator<V> A;
95     typedef test_compare<std::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(distance(m.begin(), m.end()) == 3);
101     assert(*m.begin() == V(1, 1));
102     assert(*next(m.begin()) == V(2, 1));
103     assert(*next(m.begin(), 2) == V(3, 1));
104     assert(m.get_allocator() == a);
105     }
106 #endif
107 #endif
108 }
109