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
42 changes: 16 additions & 26 deletions stl/inc/flat_map
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,6 @@ _STL_DISABLE_CLANG_WARNINGS
#undef msvc

_STD_BEGIN
template <class _Key, class _Mapped, class _KeyCompare>
struct _Flat_map_value_compare_provider {
struct value_compare {
public:
_NODISCARD bool operator()(
pair<const _Key&, const _Mapped&> _Left, pair<const _Key&, const _Mapped&> _Right) const {
return _Key_comparator(_Left.first, _Right.first);
}

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

private:
_KeyCompare _Key_comparator;
};
};

template <class _KeyContainer, class _MappedContainer>
struct _Flat_map_container_provider {
struct containers {
_KeyContainer keys;
_MappedContainer values;
};
};

// Implementation

template <bool _IsUnique, class _Key, class _Mapped, class _Compare, class _KeyContainer, class _MappedContainer>
Expand Down Expand Up @@ -342,8 +318,22 @@ public:
"mapped_container_type must support random-access iterators in order to be adapted. "
"(N5014 [flat.map.overview]/7, [flat.multimap.overview]/7)");

using value_compare = _Flat_map_value_compare_provider<key_type, mapped_type, key_compare>::value_compare;
using containers = _Flat_map_container_provider<key_container_type, mapped_container_type>::containers;
struct 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:
key_compare _Key_comparator;
};

struct containers {
key_container_type keys;
mapped_container_type values;
};

public:
// [flat.map.cons] Constructors
Expand Down
5 changes: 5 additions & 0 deletions tests/std/tests/P0429R9_flat_map/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

using namespace std;

// See GH-5965: Speculative resolution of LWG-3963 "Different flat_(multi)map specializations
// should be able to share same nested classes" is not likely to be accepted
static_assert(!is_same_v<flat_map<int, int>::containers, flat_multimap<int, int>::containers>);
static_assert(!is_same_v<flat_map<int, int>::value_compare, flat_multimap<int, int>::value_compare>);

Comment thread
StephanTLavavej marked this conversation as resolved.
template <class T, template <class...> class Tmpl>
constexpr bool is_specialization_v = false;
template <template <class...> class Tmpl, class... Ts>
Expand Down
30 changes: 13 additions & 17 deletions tests/std/tests/P0429R9_flat_map_ms_specific/test.compile.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ 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>
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>;

template <bool IsUnique, class Comparator, class Alloc1, class Alloc2>
void test_scary_ness_one() {
using Iter = flat_map<int, int>::iterator;
Expand All @@ -63,23 +67,15 @@ void test_scary_ness_one() {
flat_map_unique_if<IsUnique, int, int, Comparator, vector<int, Alloc1>, vector<int, Alloc2>>::const_iterator;
static_assert(is_same_v<ConstIter, OtherConstIter>);

using Cont = flat_map<int, int, less<int>, vector<int, Alloc1>, vector<int, Alloc2>>::containers;
using OtherCont =
flat_map_unique_if<IsUnique, int, int, Comparator, vector<int, Alloc1>, vector<int, Alloc2>>::containers;
static_assert(is_same_v<Cont, OtherCont>);

using ValueComp = flat_map<int, int, Comparator, vector<int, Alloc1>, vector<int, Alloc2>>::value_compare;
using OtherValueComp1 =
flat_map_unique_if<IsUnique, int, int, Comparator, vector<int, Alloc1>, vector<int, Alloc2>>::value_compare;
using OtherValueComp2 = flat_map_unique_if<IsUnique, int, int, Comparator, vector<int>, vector<int>>::value_compare;
using OtherValueComp3 =
flat_map_unique_if<IsUnique, int, int, Comparator, vector<int, Alloc1>, deque<int, Alloc2>>::value_compare;
using OtherValueComp4 =
flat_map_unique_if<IsUnique, int, int, Comparator, deque<int, Alloc1>, vector<int, Alloc2>>::value_compare;
static_assert(is_same_v<ValueComp, OtherValueComp1>);
static_assert(is_same_v<ValueComp, OtherValueComp2>);
static_assert(is_same_v<ValueComp, OtherValueComp3>);
static_assert(is_same_v<ValueComp, OtherValueComp4>);
using Cont = flat_map_unique_if<IsUnique, int, int, Comparator, vector<int, Alloc1>, vector<int, Alloc2>>;
using OtherCont1 = flat_map_unique_if<!IsUnique, int, int, Comparator, vector<int, Alloc1>, vector<int, Alloc2>>;
using OtherCont2 = flat_map_unique_if<IsUnique, int, int, Comparator, deque<int>, deque<int>>;
using OtherCont3 = flat_map_unique_if<IsUnique, int, int, Comparator, vector<int, Alloc1>, deque<int, Alloc2>>;
using OtherCont4 = flat_map_unique_if<IsUnique, int, int, Comparator, deque<int, Alloc1>, vector<int, Alloc2>>;
static_assert(has_different_nested_types<Cont, OtherCont1>);
static_assert(has_different_nested_types<Cont, OtherCont2>);
static_assert(has_different_nested_types<Cont, OtherCont3>);
static_assert(has_different_nested_types<Cont, OtherCont4>);
}

void test_scary_ness() {
Expand Down