• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // map(const map& m, const allocator_type& a);
15 
16 #include <map>
17 #include <cassert>
18 
19 #include "../../../test_compare.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22 
main()23 int main()
24 {
25     {
26     typedef std::pair<const int, double> V;
27     V ar[] =
28     {
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_compare<std::less<int> > C;
40     typedef test_allocator<V> A;
41     std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
42     std::map<int, double, C, A> m(mo, A(3));
43     assert(m.get_allocator() == A(3));
44     assert(m.key_comp() == C(5));
45     assert(m.size() == 3);
46     assert(distance(m.begin(), m.end()) == 3);
47     assert(*m.begin() == V(1, 1));
48     assert(*next(m.begin()) == V(2, 1));
49     assert(*next(m.begin(), 2) == V(3, 1));
50 
51     assert(mo.get_allocator() == A(7));
52     assert(mo.key_comp() == C(5));
53     assert(mo.size() == 3);
54     assert(distance(mo.begin(), mo.end()) == 3);
55     assert(*mo.begin() == V(1, 1));
56     assert(*next(mo.begin()) == V(2, 1));
57     assert(*next(mo.begin(), 2) == V(3, 1));
58     }
59 #if TEST_STD_VER >= 11
60     {
61     typedef std::pair<const int, double> V;
62     V ar[] =
63     {
64         V(1, 1),
65         V(1, 1.5),
66         V(1, 2),
67         V(2, 1),
68         V(2, 1.5),
69         V(2, 2),
70         V(3, 1),
71         V(3, 1.5),
72         V(3, 2),
73     };
74     typedef test_compare<std::less<int> > C;
75     typedef min_allocator<V> A;
76     std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
77     std::map<int, double, C, A> m(mo, A());
78     assert(m.get_allocator() == A());
79     assert(m.key_comp() == C(5));
80     assert(m.size() == 3);
81     assert(distance(m.begin(), m.end()) == 3);
82     assert(*m.begin() == V(1, 1));
83     assert(*next(m.begin()) == V(2, 1));
84     assert(*next(m.begin(), 2) == V(3, 1));
85 
86     assert(mo.get_allocator() == A());
87     assert(mo.key_comp() == C(5));
88     assert(mo.size() == 3);
89     assert(distance(mo.begin(), mo.end()) == 3);
90     assert(*mo.begin() == V(1, 1));
91     assert(*next(mo.begin()) == V(2, 1));
92     assert(*next(mo.begin(), 2) == V(3, 1));
93     }
94     {
95     typedef std::pair<const int, double> V;
96     V ar[] =
97     {
98         V(1, 1),
99         V(1, 1.5),
100         V(1, 2),
101         V(2, 1),
102         V(2, 1.5),
103         V(2, 2),
104         V(3, 1),
105         V(3, 1.5),
106         V(3, 2),
107     };
108     typedef test_compare<std::less<int> > C;
109     typedef explicit_allocator<V> A;
110     std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A{});
111     std::map<int, double, C, A> m(mo, A{});
112     assert(m.get_allocator() == A());
113     assert(m.key_comp() == C(5));
114     assert(m.size() == 3);
115     assert(distance(m.begin(), m.end()) == 3);
116     assert(*m.begin() == V(1, 1));
117     assert(*next(m.begin()) == V(2, 1));
118     assert(*next(m.begin(), 2) == V(3, 1));
119 
120     assert(mo.get_allocator() == A());
121     assert(mo.key_comp() == C(5));
122     assert(mo.size() == 3);
123     assert(distance(mo.begin(), mo.end()) == 3);
124     assert(*mo.begin() == V(1, 1));
125     assert(*next(mo.begin()) == V(2, 1));
126     assert(*next(mo.begin(), 2) == V(3, 1));
127     }
128 #endif
129 }
130