Skip to content

Commit 326be4d

Browse files
committed
review
1 parent 2537898 commit 326be4d

File tree

3 files changed

+21
-44
lines changed

3 files changed

+21
-44
lines changed

libcxx/include/__flat_set/flat_set.h

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161
#include <__utility/scope_guard.h>
6262
#include <__vector/vector.h>
6363
#include <initializer_list>
64-
#include <stdexcept>
65-
#include <type_traits>
6664

6765
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
6866
# pragma GCC system_header
@@ -173,31 +171,31 @@ class flat_set {
173171
template <class _Allocator>
174172
requires uses_allocator<container_type, _Allocator>::value
175173
_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_() {}
177175

178176
template <class _Allocator>
179177
requires uses_allocator<container_type, _Allocator>::value
180178
_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) {}
182180

183181
template <class _Allocator>
184182
requires uses_allocator<container_type, _Allocator>::value
185183
_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_() {
187185
__sort_and_unique();
188186
}
189187

190188
template <class _Allocator>
191189
requires uses_allocator<container_type, _Allocator>::value
192190
_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) {
194192
__sort_and_unique();
195193
}
196194

197195
template <class _Allocator>
198196
requires uses_allocator<container_type, _Allocator>::value
199197
_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_() {
201199
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
202200
__is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
203201
}
@@ -206,23 +204,25 @@ class flat_set {
206204
requires uses_allocator<container_type, _Allocator>::value
207205
_LIBCPP_HIDE_FROM_ABI
208206
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) {
210208
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
211209
__is_sorted_and_unique(__keys_), "Either the key container is not sorted or it contains duplicates");
212210
}
213211

214212
template <class _Allocator>
215213
requires uses_allocator<container_type, _Allocator>::value
216214
_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_) {}
218217

219218
template <class _Allocator>
220219
requires uses_allocator<container_type, _Allocator>::value
221220
_LIBCPP_HIDE_FROM_ABI flat_set(flat_set&& __other, const _Allocator& __alloc)
222221
# if _LIBCPP_HAS_EXCEPTIONS
223222
try
224223
# 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_)) {
226226
__other.clear();
227227
# if _LIBCPP_HAS_EXCEPTIONS
228228
} catch (...) {
@@ -234,24 +234,25 @@ class flat_set {
234234
template <class _InputIterator, class _Allocator>
235235
requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
236236
_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_() {
238238
insert(__first, __last);
239239
}
240240

241241
template <class _InputIterator, class _Allocator>
242242
requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
243243
_LIBCPP_HIDE_FROM_ABI
244244
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) {
246246
insert(__first, __last);
247247
}
248248

249249
template <class _InputIterator, class _Allocator>
250250
requires(__has_input_iterator_category<_InputIterator>::value && uses_allocator<container_type, _Allocator>::value)
251251
_LIBCPP_HIDE_FROM_ABI
252252
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");
255256
}
256257

257258
template <class _InputIterator, class _Allocator>
@@ -262,21 +263,22 @@ class flat_set {
262263
_InputIterator __last,
263264
const key_compare& __comp,
264265
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");
267269
}
268270

269271
template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
270272
requires uses_allocator<container_type, _Allocator>::value
271273
_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_() {
273275
insert_range(std::forward<_Range>(__rg));
274276
}
275277

276278
template <_ContainerCompatibleRange<value_type> _Range, class _Allocator>
277279
requires uses_allocator<container_type, _Allocator>::value
278280
_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) {
280282
insert_range(std::forward<_Range>(__rg));
281283
}
282284

@@ -593,26 +595,6 @@ class flat_set {
593595
friend _LIBCPP_HIDE_FROM_ABI void swap(flat_set& __x, flat_set& __y) noexcept { __x.swap(__y); }
594596

595597
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-
616598
_LIBCPP_HIDE_FROM_ABI bool __is_sorted_and_unique(auto&& __key_container) const {
617599
auto __greater_or_equal_to = [this](const auto& __x, const auto& __y) { return !__compare_(__x, __y); };
618600
return ranges::adjacent_find(__key_container, __greater_or_equal_to) == ranges::end(__key_container);
@@ -636,6 +618,7 @@ class flat_set {
636618
_LIBCPP_HIDE_FROM_ABI void __append(_Range&& __rng) {
637619
if constexpr (requires { __keys_.insert_range(__keys_.end(), std::forward<_Range>(__rng)); }) {
638620
// C++23 Sequence Container should have insert_range member function
621+
// Note that not all Sequence Containers provide append_range.
639622
__keys_.insert_range(__keys_.end(), std::forward<_Range>(__rng));
640623
} else if constexpr (ranges::common_range<_Range>) {
641624
__keys_.insert(__keys_.end(), ranges::begin(__rng), ranges::end(__rng));

libcxx/include/module.modulemap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,10 +1277,6 @@ module std [system] {
12771277
export std.vector.vector
12781278
export std.vector.fwd
12791279
}
1280-
module sorted_unique {
1281-
header "__flat_map/sorted_unique.h"
1282-
export *
1283-
}
12841280

12851281
header "flat_set"
12861282
export std.flat_map.sorted_unique

libcxx/test/std/containers/container.adaptors/flat.set/flat.set.modifiers/swap_free.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "test_macros.h"
2525
#include "../helpers.h"
2626

27-
#include "check_assertion.h"
28-
2927
// test noexcept
3028

3129
template <class T>

0 commit comments

Comments
 (0)