diff --git a/stl/inc/flat_map b/stl/inc/flat_map index 503a6573f7c..9f9c0fd3640 100644 --- a/stl/inc/flat_map +++ b/stl/inc/flat_map @@ -330,22 +330,22 @@ public: static_assert(is_same_v, "key_type and key_container_type::value_type must be the same. " - "(N5014 [flat.map.overview]/8, [flat.multimap.overview]/8)"); + "(N5032 [flat.map.overview]/8, [flat.multimap.overview]/8)"); static_assert(is_same_v, "mapped_type and mapped_container_type::value_type must be the same. " - "(N5014 [flat.map.overview]/8, [flat.multimap.overview]/8)"); + "(N5032 [flat.map.overview]/8, [flat.multimap.overview]/8)"); static_assert(!_Is_vector_bool, "key_container_type cannot be vector because it is not a sequence container. " - "(N5014 [flat.map.overview]/7, [flat.multimap.overview]/7)"); + "(N5032 [flat.map.overview]/7, [flat.multimap.overview]/7)"); static_assert(!_Is_vector_bool, "mapped_container_type cannot be vector because it is not a sequence container. " - "(N5014 [flat.map.overview]/7, [flat.multimap.overview]/7)"); + "(N5032 [flat.map.overview]/7, [flat.multimap.overview]/7)"); static_assert(random_access_iterator, "key_container_type must support random-access iterators in order to be adapted. " - "(N5014 [flat.map.overview]/7, [flat.multimap.overview]/7)"); + "(N5032 [flat.map.overview]/7, [flat.multimap.overview]/7)"); static_assert(random_access_iterator, "mapped_container_type must support random-access iterators in order to be adapted. " - "(N5014 [flat.map.overview]/7, [flat.multimap.overview]/7)"); + "(N5032 [flat.map.overview]/7, [flat.multimap.overview]/7)"); class value_compare { public: @@ -748,7 +748,7 @@ public: _NODISCARD containers extract() && noexcept( is_nothrow_move_constructible_v && is_nothrow_move_constructible_v) /* strengthened */ { - // always clears the container (N5014 [flat.map.modifiers]/34 and [flat.multimap.overview]/4) + // always clears the container (N5032 [flat.map.modifiers]/35 and [flat.multimap.overview]/4) _Clear_guard _Always_clear{this}; return _STD move(_Data); } @@ -1104,7 +1104,8 @@ private: } // O(N) if already sorted. - const auto _Num_sorted = _RANGES is_sorted_until(_Data.keys, _Pass_key_comp()) - _Data.keys.begin(); + const auto _Num_sorted = + _STD is_sorted_until(_Data.keys.begin(), _Data.keys.end(), _Pass_key_comp()) - _Data.keys.begin(); auto _View = _View_to_mutate(); const auto _Begin_unsorted_values = _View.begin() + _Num_sorted; diff --git a/stl/inc/flat_set b/stl/inc/flat_set index bf910f4cf3c..60d723304e9 100644 --- a/stl/inc/flat_set +++ b/stl/inc/flat_set @@ -87,13 +87,13 @@ private: public: static_assert(same_as<_Kty, typename _Container::value_type>, "key_type and container_type::value_type must be the same. " - "(N5014 [flat.set.overview]/8, [flat.multiset.overview]/8)"); + "(N5032 [flat.set.overview]/8, [flat.multiset.overview]/8)"); static_assert(!_Is_vector_bool<_Container>, "vector cannot be adapted because it is not a sequence container. " - "(N5014 [flat.set.overview]/7, [flat.multiset.overview]/7)"); + "(N5032 [flat.set.overview]/7, [flat.multiset.overview]/7)"); static_assert(random_access_iterator, "Sequence containers must support random-access iterators in order to be adapted. " - "(N5014 [flat.set.overview]/7, [flat.multiset.overview]/7)"); + "(N5032 [flat.set.overview]/7, [flat.multiset.overview]/7)"); using key_type = _Kty; using value_type = _Kty; @@ -365,7 +365,7 @@ public: _NODISCARD container_type extract() && noexcept( is_nothrow_move_constructible_v) /* strengthened */ { - // always clears the container (N5014 [flat.set.modifiers]/14 and [flat.multiset.modifiers]/10) + // always clears the container (N5032 [flat.set.modifiers]/16 and [flat.multiset.modifiers]/15) _Clear_guard _Always_clear{this}; return _STD move(_Mycont); } @@ -664,7 +664,7 @@ private: template _NODISCARD size_type _Erase_if(_Pred _Predicate) { - // Maintain invariants when an exception is thrown (N5014 [flat.set.erasure]/5, [flat.multiset.erasure]/5) + // Maintain invariants when an exception is thrown (N5032 [flat.set.erasure]/5, [flat.multiset.erasure]/5) _Clear_guard _Guard{this}; const auto _Erased_count = _STD _Erase_remove_if(_Mycont, _Predicate); _Guard._Target = nullptr; diff --git a/tests/std/tests/P0429R9_flat_map/test.cpp b/tests/std/tests/P0429R9_flat_map/test.cpp index 7be0b081067..fbd797b28be 100644 --- a/tests/std/tests/P0429R9_flat_map/test.cpp +++ b/tests/std/tests/P0429R9_flat_map/test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ void assert_all_requirements(const T& s) { assert_noexcept_requirements(s); assert_noexcept_requirements(const_cast(s)); - assert_is_sorted_maybe_unique<_Is_specialization_v>(s); + assert_is_sorted_maybe_unique>(s); } template @@ -63,8 +64,7 @@ template [[nodiscard]] bool check_content(const T& obj, const type_identity_t& expected) { assert_all_requirements(obj); if (!ranges::equal(obj, expected)) { - println(stderr, "Unexpected content!\nExpected {}", expected); - println(stderr, "Actual {}", obj); + println(stderr, "Unexpected content!\nExpected {}\nActual {}", expected, obj); return false; } return true; @@ -108,8 +108,8 @@ template assert(ranges::adjacent_find(subranges, is_gap_or_overlap) == subranges.end()); } - return ranges::all_of(subranges, [&expected, &actual](const subrange_t& subrange) { - const auto& [first_index, last_index, type] = subrange; + return ranges::all_of(subranges, [&expected, &actual](const subrange_t& sr) { + const auto& [first_index, last_index, type] = sr; const ranges::subrange actual_subrange{actual.begin() + first_index, actual.begin() + last_index + 1}; const ranges::subrange expected_subrange{expected.begin() + first_index, expected.begin() + last_index + 1}; @@ -122,28 +122,31 @@ template } template -class MyAllocator : public allocator { +class MyAllocator { public: using value_type = T; - using allocator::allocator; - static size_t getActiveAllocationCount() { - return s_allocations.load(); - } + MyAllocator() = default; + template + MyAllocator(const MyAllocator&) noexcept {} - T* allocate(size_t n) { - ++s_allocations; - return allocator::allocate(n); + [[nodiscard]] static size_t getActiveAllocationCount() { + return s_allocations.load(); } - T* allocate_at_least(size_t n) { + [[nodiscard]] T* allocate(size_t n) { ++s_allocations; - return allocator::allocate_at_least(n); + return allocator{}.allocate(n); } void deallocate(T* p, size_t n) noexcept { --s_allocations; - allocator::deallocate(p, n); + allocator{}.deallocate(p, n); + } + + template + [[nodiscard]] friend constexpr bool operator==(const MyAllocator&, const MyAllocator&) noexcept { + return true; } private: @@ -164,9 +167,9 @@ struct almost_pair { }; namespace std { - template + template struct tuple_element> { - using type = conditional_t; + using type = conditional_t; }; } // namespace std @@ -178,7 +181,7 @@ class Packaged { public: Packaged() : value() {} template - requires constructible_from + requires constructible_from Packaged(U&& u) : value(forward(u)) {} T get() const { @@ -260,10 +263,9 @@ void test_construction() { { // Test flat_map() and flat_map(const key_compare&) - const less compare; { flat_map fmap; - flat_map fmap1(compare); + flat_map fmap1(less{}); assert(check_key_content(fmap, {})); assert(check_value_content(fmap, {})); @@ -271,7 +273,7 @@ void test_construction() { } { flat_multimap fmmap; - flat_multimap fmmap1(compare); + flat_multimap fmmap1(less{}); assert(check_key_content(fmmap, {})); assert(check_value_content(fmmap, {})); @@ -283,9 +285,9 @@ void test_construction() { // and flat_map(const key_comp&, const alloc&) { MyAllocatorCounter allocation_counter; - flat_map fmap(MyAllocator{}); + flat_map_my_allocator fmap(MyAllocator{}); assert(!allocation_counter.check_then_reset()); - flat_map fmap1(less{}, MyAllocator{}); + flat_map_my_allocator fmap1(less{}, MyAllocator{}); assert(!allocation_counter.check_then_reset()); assert(check_key_content(fmap, {})); @@ -294,9 +296,9 @@ void test_construction() { } { MyAllocatorCounter allocation_counter; - flat_multimap fmmap(MyAllocator{}); + flat_multimap_my_allocator fmmap(MyAllocator{}); assert(!allocation_counter.check_then_reset()); - flat_multimap fmmap1(less{}, MyAllocator{}); + flat_multimap_my_allocator fmmap1(less{}, MyAllocator{}); assert(!allocation_counter.check_then_reset()); assert(check_key_content(fmmap, {})); @@ -447,7 +449,7 @@ void test_construction() { assert(check_key_content(fmmap, {0, 1, 2, 2, 3, 4})); assert(check_value_content( - fmmap, {44, 2324, 635462, 7, 433, 5})); // guaranteed by N4971 [flat.multimap.cons]/6 + fmmap, {44, 2324, 635462, 7, 433, 5})); // guaranteed by N5032 [flat.multimap.cons]/3 assert(fmmap == fmmap1); } { @@ -461,7 +463,7 @@ void test_construction() { } { // Test flat_map(_Sorted_t, const key_cont&, const mapped_cont&, const key_comp&, const alloc&) - // and flat_map(_Sorted_t, const key_cont&, const mapped_cont&, const alloc&) + // and flat_map(_Sorted_t, const key_cont&, const mapped_cont&, const alloc&) { KeyCont> keys = {0, 1, 2, 3, 4}; MappedCont> vals = {44, 2324, 635462, 433, 5}; @@ -622,7 +624,7 @@ void test_construction() { } { // Test flat_map(_Sorted_t, iter, iter, const key_comp&, const alloc&) - // and flat_map(_Sorted_t, iter, iter, const alloc&) + // and flat_map(_Sorted_t, iter, iter, const alloc&) { almost_pair value_types[]{{0, 44}, {1, 2324}, {2, 635462}, {3, 433}, {4, 5}}; @@ -871,16 +873,18 @@ void test_construction() { template