Skip to content

Commit 137cfef

Browse files
committed
review
1 parent 408c2dd commit 137cfef

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Implemented Papers
4343
- P1361R2: Integration of chrono with text formatting (`Github <https://github.com/llvm/llvm-project/issues/100014>`__)
4444
- P2255R2: A type trait to detect reference binding to temporary (implemented the type traits only) (`Github <https://github.com/llvm/llvm-project/issues/105180>`__)
4545
- P2562R1: ``constexpr`` Stable Sorting (`Github <https://github.com/llvm/llvm-project/issues/105360>`__)
46-
- P1222R4: A Standard ``flat_set`` is partially implemented and ``flat_set`` is provided (`Github <https://github.com/llvm/llvm-project/issues/105193>`__)
4746
- P0472R3: Put std::monostate in <utility> (`Github <https://github.com/llvm/llvm-project/issues/127874>`__)
47+
- P1222R4: A Standard ``flat_set`` (`Github <https://github.com/llvm/llvm-project/issues/105193>`__)
4848

4949
Improvements and New Features
5050
-----------------------------

libcxx/include/__flat_set/flat_multiset.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <__iterator/concepts.h>
4242
#include <__iterator/distance.h>
4343
#include <__iterator/iterator_traits.h>
44+
#include <__iterator/prev.h>
4445
#include <__iterator/ranges_iterator_traits.h>
4546
#include <__iterator/reverse_iterator.h>
4647
#include <__memory/allocator_traits.h>
@@ -442,7 +443,7 @@ class flat_multiset {
442443
return iterator(__key_iter);
443444
}
444445

445-
// iterator and const_iterator are the same type
446+
// The following overload is the same as the iterator overload
446447
// iterator erase(const_iterator __position);
447448

448449
_LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) {
@@ -473,7 +474,7 @@ class flat_multiset {
473474
// warning: The spec has unconditional noexcept, which means that
474475
// if any of the following functions throw an exception,
475476
// std::terminate will be called
476-
// This is discussed in P2767, which hasn't been voted on yet.
477+
// This is discussed in P3567, which hasn't been voted on yet.
477478
ranges::swap(__compare_, __y.__compare_);
478479
ranges::swap(__keys_, __y.__keys_);
479480
}
@@ -597,15 +598,13 @@ class flat_multiset {
597598
auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; });
598599
size_type __old_size = size();
599600
__flat_set_utils::__append(*this, std::forward<_Args>(__args)...);
600-
if (size() != __old_size) {
601-
if constexpr (!_WasSorted) {
602-
ranges::sort(__keys_.begin() + __old_size, __keys_.end(), __compare_);
603-
} else {
604-
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
605-
ranges::is_sorted(__keys_ | ranges::views::drop(__old_size)), "Key container is not sorted");
606-
}
607-
ranges::inplace_merge(__keys_.begin(), __keys_.begin() + __old_size, __keys_.end(), __compare_);
601+
if constexpr (!_WasSorted) {
602+
ranges::sort(__keys_.begin() + __old_size, __keys_.end(), __compare_);
603+
} else {
604+
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
605+
ranges::is_sorted(__keys_ | ranges::views::drop(__old_size)), "Key container is not sorted");
608606
}
607+
ranges::inplace_merge(__keys_.begin(), __keys_.begin() + __old_size, __keys_.end(), __compare_);
609608
__on_failure.__complete();
610609
}
611610

@@ -621,7 +620,7 @@ class flat_multiset {
621620
auto __next_smaller = __hint != cend() && __compare_(*__hint, __key);
622621

623622
if (!__prev_larger && !__next_smaller) [[likely]] {
624-
// hint correct, just use exact hint iterators
623+
// hint correct, just use exact hint iterator
625624
} else if (__prev_larger && !__next_smaller) {
626625
// the hint position is more to the right than the key should have been.
627626
// we want to emplace the element to a position as right as possible

libcxx/include/__flat_set/utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ struct __flat_set_utils {
4949
return typename decay_t<_Set>::iterator(std::move(__key_it));
5050
}
5151

52-
// TODO: We could optimize this, see
53-
// https://github.com/llvm/llvm-project/issues/108624
5452
template <class _Set, class _InputIterator>
5553
_LIBCPP_HIDE_FROM_ABI static void __append(_Set& __set, _InputIterator __first, _InputIterator __last) {
5654
__set.__keys_.insert(__set.__keys_.end(), std::move(__first), std::move(__last));

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/copy_alloc.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
// flat_multiset(const flat_multiset&, const allocator_type&);
1414

15+
#include <algorithm>
1516
#include <cassert>
1617
#include <deque>
1718
#include <flat_set>

libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/initializer_list.pass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// template<class Alloc>
1717
// flat_multiset(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
1818

19+
#include <algorithm>
1920
#include <cassert>
2021
#include <deque>
2122
#include <flat_set>

libcxx/test/std/containers/container.adaptors/flat.multiset/helpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef SUPPORT_flat_multiset_HELPERS_H
10-
#define SUPPORT_flat_multiset_HELPERS_H
9+
#ifndef SUPPORT_FLAT_MULTISET_HELPERS_H
10+
#define SUPPORT_FLAT_MULTISET_HELPERS_H
1111

1212
#include <algorithm>
1313
#include <cassert>
@@ -298,4 +298,4 @@ class Moveable {
298298
bool moved() const { return int_ == -1; }
299299
};
300300

301-
#endif // SUPPORT_flat_multiset_HELPERS_H
301+
#endif // SUPPORT_FLAT_MULTISET_HELPERS_H

0 commit comments

Comments
 (0)