]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / associative / map / map.cons / iter_iter_comp_alloc.pass.cpp
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_macros.h"
22 #include "../../../test_compare.h"
23 #include "test_allocator.h"
24 #include "min_allocator.h"
25
26 int main()
27 {
28     {
29     typedef std::pair<const int, double> V;
30     V ar[] =
31     {
32         V(1, 1),
33         V(1, 1.5),
34         V(1, 2),
35         V(2, 1),
36         V(2, 1.5),
37         V(2, 2),
38         V(3, 1),
39         V(3, 1.5),
40         V(3, 2),
41     };
42     typedef test_compare<std::less<int> > C;
43     typedef test_allocator<V> A;
44     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
45     assert(m.get_allocator() == A(7));
46     assert(m.key_comp() == C(5));
47     assert(m.size() == 3);
48     assert(distance(m.begin(), m.end()) == 3);
49     assert(*m.begin() == V(1, 1));
50     assert(*next(m.begin()) == V(2, 1));
51     assert(*next(m.begin(), 2) == V(3, 1));
52     }
53 #if TEST_STD_VER >= 11
54     {
55     typedef std::pair<const int, double> V;
56     V ar[] =
57     {
58         V(1, 1),
59         V(1, 1.5),
60         V(1, 2),
61         V(2, 1),
62         V(2, 1.5),
63         V(2, 2),
64         V(3, 1),
65         V(3, 1.5),
66         V(3, 2),
67     };
68     typedef test_compare<std::less<int> > C;
69     typedef min_allocator<V> A;
70     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
71     assert(m.get_allocator() == A());
72     assert(m.key_comp() == C(5));
73     assert(m.size() == 3);
74     assert(distance(m.begin(), m.end()) == 3);
75     assert(*m.begin() == V(1, 1));
76     assert(*next(m.begin()) == V(2, 1));
77     assert(*next(m.begin(), 2) == V(3, 1));
78     }
79 #if TEST_STD_VER > 11
80     {
81     typedef std::pair<const int, double> V;
82     V ar[] =
83     {
84         V(1, 1),
85         V(1, 1.5),
86         V(1, 2),
87         V(2, 1),
88         V(2, 1.5),
89         V(2, 2),
90         V(3, 1),
91         V(3, 1.5),
92         V(3, 2),
93     };
94     {
95     typedef std::pair<const int, double> V;
96     typedef min_allocator<V> A;
97     typedef test_compare<std::less<int> > C;
98     A a;
99     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a );
100
101     assert(m.size() == 3);
102     assert(distance(m.begin(), m.end()) == 3);
103     assert(*m.begin() == V(1, 1));
104     assert(*next(m.begin()) == V(2, 1));
105     assert(*next(m.begin(), 2) == V(3, 1));
106     assert(m.get_allocator() == a);
107     }
108     {
109     typedef std::pair<const int, double> V;
110     typedef explicit_allocator<V> A;
111     typedef test_compare<std::less<int> > C;
112     A a;
113     std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a );
114
115     assert(m.size() == 3);
116     assert(distance(m.begin(), m.end()) == 3);
117     assert(*m.begin() == V(1, 1));
118     assert(*next(m.begin()) == V(2, 1));
119     assert(*next(m.begin(), 2) == V(3, 1));
120     assert(m.get_allocator() == a);
121     }
122     }
123 #endif
124 #endif
125 }