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