1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
20 #include "test_macros.h"
21 #include "../../../test_compare.h"
22 #include "test_allocator.h"
23 #include "min_allocator.h"
27 typedef std::pair
<const int, double> V
;
29 typedef test_less
<int> C
;
30 typedef test_allocator
<V
> A
;
31 std::map
<int, double, C
, A
> mo(C(5), A(7));
32 std::map
<int, double, C
, A
> m
= std::move(mo
);
33 assert(m
.get_allocator() == A(7));
34 assert(m
.key_comp() == C(5));
35 assert(m
.size() == 0);
36 assert(std::distance(m
.begin(), m
.end()) == 0);
38 assert(mo
.get_allocator() == A(7));
39 assert(mo
.get_allocator().get_id() == test_alloc_base::moved_value
);
40 assert(mo
.key_comp() == C(5));
41 assert(mo
.size() == 0);
42 assert(std::distance(mo
.begin(), mo
.end()) == 0);
57 typedef test_less
<int> C
;
58 typedef test_allocator
<V
> A
;
59 std::map
<int, double, C
, A
> mo(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]), C(5), A(7));
60 std::map
<int, double, C
, A
> m
= std::move(mo
);
61 assert(m
.get_allocator() == A(7));
62 assert(m
.key_comp() == C(5));
63 assert(m
.size() == 3);
64 assert(std::distance(m
.begin(), m
.end()) == 3);
65 assert(*m
.begin() == V(1, 1));
66 assert(*std::next(m
.begin()) == V(2, 1));
67 assert(*std::next(m
.begin(), 2) == V(3, 1));
69 assert(mo
.get_allocator() == A(7));
70 assert(mo
.get_allocator().get_id() == test_alloc_base::moved_value
);
71 assert(mo
.key_comp() == C(5));
72 assert(mo
.size() == 0);
73 assert(std::distance(mo
.begin(), mo
.end()) == 0);
76 typedef test_less
<int> C
;
77 typedef min_allocator
<V
> A
;
78 std::map
<int, double, C
, A
> mo(C(5), A());
79 std::map
<int, double, C
, A
> m
= std::move(mo
);
80 assert(m
.get_allocator() == A());
81 assert(m
.key_comp() == C(5));
82 assert(m
.size() == 0);
83 assert(std::distance(m
.begin(), m
.end()) == 0);
85 assert(mo
.get_allocator() == A());
86 assert(mo
.key_comp() == C(5));
87 assert(mo
.size() == 0);
88 assert(std::distance(mo
.begin(), mo
.end()) == 0);
103 typedef test_less
<int> C
;
104 typedef min_allocator
<V
> A
;
105 std::map
<int, double, C
, A
> mo(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]), C(5), A());
106 std::map
<int, double, C
, A
> m
= std::move(mo
);
107 assert(m
.get_allocator() == A());
108 assert(m
.key_comp() == C(5));
109 assert(m
.size() == 3);
110 assert(std::distance(m
.begin(), m
.end()) == 3);
111 assert(*m
.begin() == V(1, 1));
112 assert(*std::next(m
.begin()) == V(2, 1));
113 assert(*std::next(m
.begin(), 2) == V(3, 1));
115 assert(mo
.get_allocator() == A());
116 assert(mo
.key_comp() == C(5));
117 assert(mo
.size() == 0);
118 assert(std::distance(mo
.begin(), mo
.end()) == 0);