Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions stl/inc/flat_map
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,17 @@ public:
"mapped_container_type must support random-access iterators in order to be adapted. "
"(N5014 [flat.map.overview]/7, [flat.multimap.overview]/7)");

struct value_compare {
class value_compare {
public:
_NODISCARD bool operator()(const_reference _Left, const_reference _Right) const {
return _Key_comparator(_Left.first, _Right.first);
}

value_compare(key_compare _Comp) : _Key_comparator(_Comp) {}

private:
friend _Flat_map_base;

value_compare(const key_compare& _Comp) : _Key_comparator(_Comp) {}

key_compare _Key_comparator;
};

Expand Down Expand Up @@ -902,19 +904,19 @@ protected:
if constexpr (_IsUnique) {
if (_Key_it != _Data.keys.begin() && !_Key_compare(*(_Key_it - 1), _STD forward<_OtherKey>(_Key_val))) {
// Previous element is equivalent to key, no insert needed
return {this->begin() + (_Index - 1), false};
return {begin() + (_Index - 1), false};
}
}

// Need to insert
key_type _Key_to_insert(_STD forward<_OtherKey>(_Key_val));
mapped_type _Mapped_to_insert(_STD forward<_MappedArgTypes>(_Mapped_args)...);
_Insert_exact(this->cbegin() + _Index, _STD move(_Key_to_insert), _STD move(_Mapped_to_insert));
_Insert_exact(cbegin() + _Index, _STD move(_Key_to_insert), _STD move(_Mapped_to_insert));

if constexpr (_IsUnique) {
return {this->begin() + _Index, true};
return {begin() + _Index, true};
} else {
return this->begin() + _Index;
return begin() + _Index;
}
}

Expand Down Expand Up @@ -986,7 +988,7 @@ protected:
}
}

const auto _Dist = _New_position - this->begin();
const auto _Dist = _New_position - begin();
{
key_type _Key_to_insert(_STD forward<_OtherKey>(_Key_val));
mapped_type _Mapped_to_insert(_STD forward<_MappedArgTypes>(_Args)...);
Expand Down Expand Up @@ -1260,20 +1262,20 @@ public:
mapped_type& operator[](const key_type& _Key_val)
requires is_default_constructible_v<mapped_type>
{
return this->try_emplace(_Key_val).first->second;
return try_emplace(_Key_val).first->second;
}
mapped_type& operator[](key_type&& _Key_val)
requires is_default_constructible_v<mapped_type>
{
return this->try_emplace(_STD move(_Key_val)).first->second;
return try_emplace(_STD move(_Key_val)).first->second;
}

template <class _OtherKey>
mapped_type& operator[](_OtherKey&& _Key_val)
requires _Transparent<key_compare> && is_constructible_v<key_type, _OtherKey>
&& is_default_constructible_v<mapped_type>
{
return this->try_emplace(_STD forward<_OtherKey>(_Key_val)).first->second;
return try_emplace(_STD forward<_OtherKey>(_Key_val)).first->second;
}

_NODISCARD mapped_type& at(const key_type& _Key_val) {
Expand Down
14 changes: 7 additions & 7 deletions tests/std/tests/P0429R9_flat_map/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ constexpr bool is_specialization_v = false;
template <template <class...> class Tmpl, class... Ts>
constexpr bool is_specialization_v<Tmpl<Ts...>, Tmpl> = true;

template <typename T>
template <class T>
concept IsFlatMap =
is_specialization_v<remove_cvref_t<T>, flat_map> || is_specialization_v<remove_cvref_t<T>, flat_multimap>;

Expand Down Expand Up @@ -120,7 +120,7 @@ template <IsFlatMap T>
});
}

template <typename T>
template <class T>
class MyAllocator : public allocator<T> {
public:
using value_type = T;
Expand Down Expand Up @@ -169,14 +169,14 @@ namespace std {
};
} // namespace std

template <typename T>
template <class T>
class Packaged {
private:
T value;

public:
Packaged() : value() {}
template <typename U>
template <class U>
requires constructible_from<T, U&&>
Packaged(U&& u) : value(forward<U>(u)) {}

Expand All @@ -197,10 +197,10 @@ class Packaged {
friend auto operator<=>(const Packaged&, const Packaged&) = default;
};

template <typename T>
template <class T>
struct PackagedCompare : less<Packaged<T>> {};

template <typename T>
template <class T>
struct TransparentPackagedCompare : PackagedCompare<T> {
using is_transparent = void;

Expand Down Expand Up @@ -1183,7 +1183,7 @@ void test_throwing_compare_swap_single() {
}

// Test that changes in GH-5987 did not break calls of lookup member functions by using deducing this.
template <typename T>
template <class T>
void test_lookup_call_on_temporaries_single() {
(void) T{}.lower_bound(42);
(void) T{}.lower_bound('a');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct flat_map_unique_if_impl<false> {
template <bool IsUnique, class Key, class Mapped, class Comp, class KeyCont, class MappedCont>
using flat_map_unique_if = flat_map_unique_if_impl<IsUnique>::template type<Key, Mapped, Comp, KeyCont, MappedCont>;

template <typename A, typename B>
template <class A, class B>
constexpr bool has_different_nested_types = !is_same_v<typename A::value_compare, typename B::value_compare>
&& !is_same_v<typename A::containers, typename B::containers>;

Expand Down