61
61
#include < __utility/scope_guard.h>
62
62
#include < __vector/vector.h>
63
63
#include < initializer_list>
64
- #include < stdexcept>
65
- #include < type_traits>
66
64
67
65
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
68
66
# pragma GCC system_header
@@ -173,31 +171,31 @@ class flat_set {
173
171
template <class _Allocator >
174
172
requires uses_allocator<container_type, _Allocator>::value
175
173
_LIBCPP_HIDE_FROM_ABI explicit flat_set (const _Allocator& __alloc)
176
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc ) {}
174
+ : __keys_ (std::make_obj_using_allocator<container_type>(__alloc)), __compare_ ( ) {}
177
175
178
176
template <class _Allocator >
179
177
requires uses_allocator<container_type, _Allocator>::value
180
178
_LIBCPP_HIDE_FROM_ABI flat_set (const key_compare& __comp, const _Allocator& __alloc)
181
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {}
179
+ : __keys_ (std::make_obj_using_allocator<container_type>( __alloc)), __compare_ ( __comp) {}
182
180
183
181
template <class _Allocator >
184
182
requires uses_allocator<container_type, _Allocator>::value
185
183
_LIBCPP_HIDE_FROM_ABI flat_set (const container_type& __keys, const _Allocator& __alloc)
186
- : flat_set (__ctor_uses_allocator_tag{}, __alloc, __keys) {
184
+ : __keys_ (std::make_obj_using_allocator<container_type>( __alloc, __keys)), __compare_ ( ) {
187
185
__sort_and_unique ();
188
186
}
189
187
190
188
template <class _Allocator >
191
189
requires uses_allocator<container_type, _Allocator>::value
192
190
_LIBCPP_HIDE_FROM_ABI flat_set (const container_type& __keys, const key_compare& __comp, const _Allocator& __alloc)
193
- : flat_set (__ctor_uses_allocator_tag{}, __alloc, __keys, __comp) {
191
+ : __keys_ (std::make_obj_using_allocator<container_type>( __alloc, __keys)), __compare_ ( __comp) {
194
192
__sort_and_unique ();
195
193
}
196
194
197
195
template <class _Allocator >
198
196
requires uses_allocator<container_type, _Allocator>::value
199
197
_LIBCPP_HIDE_FROM_ABI flat_set (sorted_unique_t , const container_type& __keys, const _Allocator& __alloc)
200
- : flat_set (__ctor_uses_allocator_tag{}, __alloc, __keys) {
198
+ : __keys_ (std::make_obj_using_allocator<container_type>( __alloc, __keys)), __compare_ ( ) {
201
199
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT (
202
200
__is_sorted_and_unique (__keys_), " Either the key container is not sorted or it contains duplicates" );
203
201
}
@@ -206,23 +204,25 @@ class flat_set {
206
204
requires uses_allocator<container_type, _Allocator>::value
207
205
_LIBCPP_HIDE_FROM_ABI
208
206
flat_set (sorted_unique_t , const container_type& __keys, const key_compare& __comp, const _Allocator& __alloc)
209
- : flat_set (__ctor_uses_allocator_tag{}, __alloc, __keys, __comp) {
207
+ : __keys_ (std::make_obj_using_allocator<container_type>( __alloc, __keys)), __compare_ ( __comp) {
210
208
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT (
211
209
__is_sorted_and_unique (__keys_), " Either the key container is not sorted or it contains duplicates" );
212
210
}
213
211
214
212
template <class _Allocator >
215
213
requires uses_allocator<container_type, _Allocator>::value
216
214
_LIBCPP_HIDE_FROM_ABI flat_set (const flat_set& __other, const _Allocator& __alloc)
217
- : flat_set (__ctor_uses_allocator_tag{}, __alloc, __other.__keys_ , __other.__compare_ ) {}
215
+ : __keys_ (std::make_obj_using_allocator<container_type>(__alloc, __other.__keys_ )),
216
+ __compare_ (__other.__compare_ ) {}
218
217
219
218
template <class _Allocator >
220
219
requires uses_allocator<container_type, _Allocator>::value
221
220
_LIBCPP_HIDE_FROM_ABI flat_set (flat_set&& __other, const _Allocator& __alloc)
222
221
# if _LIBCPP_HAS_EXCEPTIONS
223
222
try
224
223
# endif // _LIBCPP_HAS_EXCEPTIONS
225
- : flat_set (__ctor_uses_allocator_tag{}, __alloc, std::move (__other.__keys_ ), std::move (__other.__compare_ )) {
224
+ : __keys_ (std::make_obj_using_allocator<container_type>(__alloc, std::move (__other.__keys_ ))),
225
+ __compare_ (std::move (__other.__compare_ )) {
226
226
__other.clear ();
227
227
# if _LIBCPP_HAS_EXCEPTIONS
228
228
} catch (...) {
@@ -234,24 +234,25 @@ class flat_set {
234
234
template <class _InputIterator , class _Allocator >
235
235
requires (__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
236
236
_LIBCPP_HIDE_FROM_ABI flat_set (_InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
237
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc ) {
237
+ : __keys_ (std::make_obj_using_allocator<container_type>(__alloc)), __compare_ ( ) {
238
238
insert (__first, __last);
239
239
}
240
240
241
241
template <class _InputIterator , class _Allocator >
242
242
requires (__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
243
243
_LIBCPP_HIDE_FROM_ABI
244
244
flat_set (_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc)
245
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
245
+ : __keys_ (std::make_obj_using_allocator<container_type>( __alloc)), __compare_ ( __comp) {
246
246
insert (__first, __last);
247
247
}
248
248
249
249
template <class _InputIterator , class _Allocator >
250
250
requires (__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
251
251
_LIBCPP_HIDE_FROM_ABI
252
252
flat_set (sorted_unique_t , _InputIterator __first, _InputIterator __last, const _Allocator& __alloc)
253
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc) {
254
- insert (sorted_unique, __first, __last);
253
+ : __keys_ (std::make_obj_using_allocator<container_type>(__alloc, __first, __last)), __compare_ () {
254
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT (
255
+ __is_sorted_and_unique (__keys_), " Either the key container is not sorted or it contains duplicates" );
255
256
}
256
257
257
258
template <class _InputIterator , class _Allocator >
@@ -262,21 +263,22 @@ class flat_set {
262
263
_InputIterator __last,
263
264
const key_compare& __comp,
264
265
const _Allocator& __alloc)
265
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
266
- insert (sorted_unique, __first, __last);
266
+ : __keys_ (std::make_obj_using_allocator<container_type>(__alloc, __first, __last)), __compare_ (__comp) {
267
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT (
268
+ __is_sorted_and_unique (__keys_), " Either the key container is not sorted or it contains duplicates" );
267
269
}
268
270
269
271
template <_ContainerCompatibleRange<value_type> _Range, class _Allocator >
270
272
requires uses_allocator<container_type, _Allocator>::value
271
273
_LIBCPP_HIDE_FROM_ABI flat_set (from_range_t , _Range&& __rg, const _Allocator& __alloc)
272
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc ) {
274
+ : __keys_ (std::make_obj_using_allocator<container_type>(__alloc)), __compare_ ( ) {
273
275
insert_range (std::forward<_Range>(__rg));
274
276
}
275
277
276
278
template <_ContainerCompatibleRange<value_type> _Range, class _Allocator >
277
279
requires uses_allocator<container_type, _Allocator>::value
278
280
_LIBCPP_HIDE_FROM_ABI flat_set (from_range_t , _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc)
279
- : flat_set (__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {
281
+ : __keys_ (std::make_obj_using_allocator<container_type>( __alloc)), __compare_ ( __comp) {
280
282
insert_range (std::forward<_Range>(__rg));
281
283
}
282
284
@@ -593,26 +595,6 @@ class flat_set {
593
595
friend _LIBCPP_HIDE_FROM_ABI void swap (flat_set& __x, flat_set& __y) noexcept { __x.swap (__y); }
594
596
595
597
private:
596
- struct __ctor_uses_allocator_tag {
597
- explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_tag () = default;
598
- };
599
- struct __ctor_uses_allocator_empty_tag {
600
- explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_empty_tag () = default;
601
- };
602
-
603
- template <class _Allocator , class _KeyCont , class ... _CompArg>
604
- requires uses_allocator<container_type, _Allocator>::value
605
- _LIBCPP_HIDE_FROM_ABI
606
- flat_set (__ctor_uses_allocator_tag, const _Allocator& __alloc, _KeyCont&& __key_cont, _CompArg&&... __comp)
607
- : __keys_ (std::make_obj_using_allocator<container_type>(__alloc, std::forward<_KeyCont>(__key_cont))),
608
- __compare_ (std::forward<_CompArg>(__comp)...) {}
609
-
610
- template <class _Allocator , class ... _CompArg>
611
- requires uses_allocator<container_type, _Allocator>::value
612
- _LIBCPP_HIDE_FROM_ABI flat_set (__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp)
613
- : __keys_ (std::make_obj_using_allocator<container_type>(__alloc)),
614
- __compare_ (std::forward<_CompArg>(__comp)...) {}
615
-
616
598
_LIBCPP_HIDE_FROM_ABI bool __is_sorted_and_unique (auto && __key_container) const {
617
599
auto __greater_or_equal_to = [this ](const auto & __x, const auto & __y) { return !__compare_ (__x, __y); };
618
600
return ranges::adjacent_find (__key_container, __greater_or_equal_to) == ranges::end (__key_container);
@@ -636,6 +618,7 @@ class flat_set {
636
618
_LIBCPP_HIDE_FROM_ABI void __append (_Range&& __rng) {
637
619
if constexpr (requires { __keys_.insert_range (__keys_.end (), std::forward<_Range>(__rng)); }) {
638
620
// C++23 Sequence Container should have insert_range member function
621
+ // Note that not all Sequence Containers provide append_range.
639
622
__keys_.insert_range (__keys_.end (), std::forward<_Range>(__rng));
640
623
} else if constexpr (ranges::common_range<_Range>) {
641
624
__keys_.insert (__keys_.end (), ranges::begin (__rng), ranges::end (__rng));
0 commit comments