23
23
#include < __algorithm/remove_if.h>
24
24
#include < __assert>
25
25
#include < __compare/synth_three_way.h>
26
- #include < __concepts/convertible_to.h>
27
26
#include < __concepts/swappable.h>
28
27
#include < __config>
29
28
#include < __cstddef/byte.h>
30
29
#include < __cstddef/ptrdiff_t.h>
30
+ #include < __flat_map/key_value_iterator.h>
31
31
#include < __flat_map/sorted_unique.h>
32
32
#include < __functional/invoke.h>
33
33
#include < __functional/is_transparent.h>
38
38
#include < __iterator/next.h>
39
39
#include < __iterator/ranges_iterator_traits.h>
40
40
#include < __iterator/reverse_iterator.h>
41
- #include < __memory/addressof.h>
42
41
#include < __memory/allocator_traits.h>
43
42
#include < __memory/uses_allocator.h>
44
43
#include < __memory/uses_allocator_construction.h>
57
56
#include < __type_traits/is_allocator.h>
58
57
#include < __type_traits/is_nothrow_constructible.h>
59
58
#include < __type_traits/is_same.h>
60
- #include < __type_traits/maybe_const.h>
61
59
#include < __utility/exception_guard.h>
60
+ #include < __utility/move.h>
62
61
#include < __utility/pair.h>
63
62
#include < __utility/scope_guard.h>
64
63
#include < __vector/vector.h>
@@ -82,9 +81,6 @@ template <class _Key,
82
81
class _KeyContainer = vector<_Key>,
83
82
class _MappedContainer = vector<_Tp>>
84
83
class flat_map {
85
- template <bool _Const>
86
- struct __iterator ;
87
-
88
84
template <class , class , class , class , class >
89
85
friend class flat_map ;
90
86
@@ -93,6 +89,9 @@ class flat_map {
93
89
static_assert (!is_same_v<_KeyContainer, std::vector<bool >>, " vector<bool> is not a sequence container" );
94
90
static_assert (!is_same_v<_MappedContainer, std::vector<bool >>, " vector<bool> is not a sequence container" );
95
91
92
+ template <bool _Const>
93
+ using __iterator = __key_value_iterator<flat_map, _KeyContainer, _MappedContainer, _Const>;
94
+
96
95
public:
97
96
// types
98
97
using key_type = _Key;
@@ -134,123 +133,6 @@ class flat_map {
134
133
135
134
_LIBCPP_HIDE_FROM_ABI static constexpr bool __is_compare_transparent = __is_transparent_v<_Compare, _Compare>;
136
135
137
- template <bool _Const>
138
- struct __iterator {
139
- private:
140
- using __key_iterator = ranges::iterator_t <const key_container_type>;
141
- using __mapped_iterator = ranges::iterator_t <__maybe_const<_Const, mapped_container_type>>;
142
- using __reference = pair<iter_reference_t <__key_iterator>, iter_reference_t <__mapped_iterator>>;
143
-
144
- struct __arrow_proxy {
145
- __reference __ref_;
146
- _LIBCPP_HIDE_FROM_ABI __reference* operator ->() { return std::addressof (__ref_); }
147
- };
148
-
149
- __key_iterator __key_iter_;
150
- __mapped_iterator __mapped_iter_;
151
-
152
- friend flat_map;
153
-
154
- public:
155
- using iterator_concept = random_access_iterator_tag;
156
- // `flat_map::iterator` only satisfy "Cpp17InputIterator" named requirements, because
157
- // its `reference` is not a reference type.
158
- // However, to avoid surprising runtime behaviour when it is used with the
159
- // Cpp17 algorithms or operations, iterator_category is set to random_access_iterator_tag.
160
- using iterator_category = random_access_iterator_tag;
161
- using value_type = flat_map::value_type;
162
- using difference_type = flat_map::difference_type;
163
-
164
- _LIBCPP_HIDE_FROM_ABI __iterator () = default;
165
-
166
- _LIBCPP_HIDE_FROM_ABI __iterator (__iterator<!_Const> __i)
167
- requires _Const && convertible_to<ranges::iterator_t<key_container_type>, __key_iterator> &&
168
- convertible_to<ranges::iterator_t<mapped_container_type>, __mapped_iterator>
169
- : __key_iter_(std::move(__i.__key_iter_)), __mapped_iter_(std::move(__i.__mapped_iter_)) {}
170
-
171
- _LIBCPP_HIDE_FROM_ABI __iterator (__key_iterator __key_iter, __mapped_iterator __mapped_iter)
172
- : __key_iter_(std::move(__key_iter)), __mapped_iter_(std::move(__mapped_iter)) {}
173
-
174
- _LIBCPP_HIDE_FROM_ABI __reference operator *() const { return __reference (*__key_iter_, *__mapped_iter_); }
175
- _LIBCPP_HIDE_FROM_ABI __arrow_proxy operator ->() const { return __arrow_proxy{**this }; }
176
-
177
- _LIBCPP_HIDE_FROM_ABI __iterator& operator ++() {
178
- ++__key_iter_;
179
- ++__mapped_iter_;
180
- return *this ;
181
- }
182
-
183
- _LIBCPP_HIDE_FROM_ABI __iterator operator ++(int ) {
184
- __iterator __tmp (*this );
185
- ++*this ;
186
- return __tmp;
187
- }
188
-
189
- _LIBCPP_HIDE_FROM_ABI __iterator& operator --() {
190
- --__key_iter_;
191
- --__mapped_iter_;
192
- return *this ;
193
- }
194
-
195
- _LIBCPP_HIDE_FROM_ABI __iterator operator --(int ) {
196
- __iterator __tmp (*this );
197
- --*this ;
198
- return __tmp;
199
- }
200
-
201
- _LIBCPP_HIDE_FROM_ABI __iterator& operator +=(difference_type __x) {
202
- __key_iter_ += __x;
203
- __mapped_iter_ += __x;
204
- return *this ;
205
- }
206
-
207
- _LIBCPP_HIDE_FROM_ABI __iterator& operator -=(difference_type __x) {
208
- __key_iter_ -= __x;
209
- __mapped_iter_ -= __x;
210
- return *this ;
211
- }
212
-
213
- _LIBCPP_HIDE_FROM_ABI __reference operator [](difference_type __n) const { return *(*this + __n); }
214
-
215
- _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator ==(const __iterator& __x, const __iterator& __y) {
216
- return __x.__key_iter_ == __y.__key_iter_ ;
217
- }
218
-
219
- _LIBCPP_HIDE_FROM_ABI friend bool operator <(const __iterator& __x, const __iterator& __y) {
220
- return __x.__key_iter_ < __y.__key_iter_ ;
221
- }
222
-
223
- _LIBCPP_HIDE_FROM_ABI friend bool operator >(const __iterator& __x, const __iterator& __y) { return __y < __x; }
224
-
225
- _LIBCPP_HIDE_FROM_ABI friend bool operator <=(const __iterator& __x, const __iterator& __y) { return !(__y < __x); }
226
-
227
- _LIBCPP_HIDE_FROM_ABI friend bool operator >=(const __iterator& __x, const __iterator& __y) { return !(__x < __y); }
228
-
229
- _LIBCPP_HIDE_FROM_ABI friend auto operator <=>(const __iterator& __x, const __iterator& __y)
230
- requires three_way_comparable<__key_iterator>
231
- {
232
- return __x.__key_iter_ <=> __y.__key_iter_ ;
233
- }
234
-
235
- _LIBCPP_HIDE_FROM_ABI friend __iterator operator +(const __iterator& __i, difference_type __n) {
236
- auto __tmp = __i;
237
- __tmp += __n;
238
- return __tmp;
239
- }
240
-
241
- _LIBCPP_HIDE_FROM_ABI friend __iterator operator +(difference_type __n, const __iterator& __i) { return __i + __n; }
242
-
243
- _LIBCPP_HIDE_FROM_ABI friend __iterator operator -(const __iterator& __i, difference_type __n) {
244
- auto __tmp = __i;
245
- __tmp -= __n;
246
- return __tmp;
247
- }
248
-
249
- _LIBCPP_HIDE_FROM_ABI friend difference_type operator -(const __iterator& __x, const __iterator& __y) {
250
- return difference_type (__x.__key_iter_ - __y.__key_iter_ );
251
- }
252
- };
253
-
254
136
public:
255
137
// [flat.map.cons], construct/copy/destroy
256
138
_LIBCPP_HIDE_FROM_ABI flat_map () noexcept (
@@ -1308,7 +1190,7 @@ template <ranges::input_range _Range,
1308
1190
class _Allocator = allocator<byte>,
1309
1191
class = __enable_if_t <!__is_allocator<_Compare>::value && __is_allocator<_Allocator>::value>>
1310
1192
flat_map (from_range_t , _Range&&, _Compare = _Compare (), _Allocator = _Allocator ())
1311
- -> flat_map<
1193
+ ->flat_map <
1312
1194
__range_key_type<_Range>,
1313
1195
__range_mapped_type<_Range>,
1314
1196
_Compare,
@@ -1317,7 +1199,7 @@ flat_map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator(
1317
1199
1318
1200
template <ranges::input_range _Range, class _Allocator , class = __enable_if_t <__is_allocator<_Allocator>::value>>
1319
1201
flat_map (from_range_t , _Range&&, _Allocator)
1320
- -> flat_map<
1202
+ ->flat_map <
1321
1203
__range_key_type<_Range>,
1322
1204
__range_mapped_type<_Range>,
1323
1205
less<__range_key_type<_Range>>,
0 commit comments