• 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);
15 
16 #include <map>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "../../../test_compare.h"
21 #include "test_allocator.h"
22 #include "min_allocator.h"
23 
main()24 int main()
25 {
26     {
27         typedef std::pair<const int, double> V;
28         V ar[] =
29         {
30             V(1, 1),
31             V(1, 1.5),
32             V(1, 2),
33             V(2, 1),
34             V(2, 1.5),
35             V(2, 2),
36             V(3, 1),
37             V(3, 1.5),
38             V(3, 2),
39         };
40         typedef test_compare<std::less<int> > C;
41         typedef test_allocator<V> A;
42         std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
43         std::map<int, double, C, A> m = mo;
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         assert(mo.get_allocator() == A(7));
53         assert(mo.key_comp() == C(5));
54         assert(mo.size() == 3);
55         assert(distance(mo.begin(), mo.end()) == 3);
56         assert(*mo.begin() == V(1, 1));
57         assert(*next(mo.begin()) == V(2, 1));
58         assert(*next(mo.begin(), 2) == V(3, 1));
59     }
60 #if TEST_STD_VER >= 11
61     {
62         typedef std::pair<const int, double> V;
63         V ar[] =
64         {
65             V(1, 1),
66             V(1, 1.5),
67             V(1, 2),
68             V(2, 1),
69             V(2, 1.5),
70             V(2, 2),
71             V(3, 1),
72             V(3, 1.5),
73             V(3, 2),
74         };
75         typedef test_compare<std::less<int> > C;
76         typedef other_allocator<V> A;
77         std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));
78         std::map<int, double, C, A> m = mo;
79         assert(m.get_allocator() == A(-2));
80         assert(m.key_comp() == C(5));
81         assert(m.size() == 3);
82         assert(distance(m.begin(), m.end()) == 3);
83         assert(*m.begin() == V(1, 1));
84         assert(*next(m.begin()) == V(2, 1));
85         assert(*next(m.begin(), 2) == V(3, 1));
86 
87         assert(mo.get_allocator() == A(7));
88         assert(mo.key_comp() == C(5));
89         assert(mo.size() == 3);
90         assert(distance(mo.begin(), mo.end()) == 3);
91         assert(*mo.begin() == V(1, 1));
92         assert(*next(mo.begin()) == V(2, 1));
93         assert(*next(mo.begin(), 2) == V(3, 1));
94     }
95     {
96         typedef std::pair<const int, double> V;
97         V ar[] =
98         {
99             V(1, 1),
100             V(1, 1.5),
101             V(1, 2),
102             V(2, 1),
103             V(2, 1.5),
104             V(2, 2),
105             V(3, 1),
106             V(3, 1.5),
107             V(3, 2),
108         };
109         typedef test_compare<std::less<int> > C;
110         typedef min_allocator<V> A;
111         std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A());
112         std::map<int, double, C, A> m = mo;
113         assert(m.get_allocator() == A());
114         assert(m.key_comp() == C(5));
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 
121         assert(mo.get_allocator() == A());
122         assert(mo.key_comp() == C(5));
123         assert(mo.size() == 3);
124         assert(distance(mo.begin(), mo.end()) == 3);
125         assert(*mo.begin() == V(1, 1));
126         assert(*next(mo.begin()) == V(2, 1));
127         assert(*next(mo.begin(), 2) == V(3, 1));
128     }
129 #endif
130 }
131