Skip to content

Commit

Permalink
<map>, <unordered_map>: Allow MapLike<K, V&> again (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored Apr 20, 2023
1 parent 06c0408 commit 0a2d59e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 0 additions & 4 deletions stl/inc/map
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public:
_MISMATCHED_ALLOCATOR_MESSAGE("map<Key, Value, Compare, Allocator>", "pair<const Key, Value>"));
static_assert(is_object_v<_Kty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");
static_assert(is_object_v<_Ty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");

using _Mybase = _Tree<_Tmap_traits<_Kty, _Ty, _Pr, _Alloc, false>>;
using _Nodeptr = typename _Mybase::_Nodeptr;
Expand Down Expand Up @@ -463,8 +461,6 @@ public:
_MISMATCHED_ALLOCATOR_MESSAGE("multimap<Key, Value, Compare, Allocator>", "pair<const Key, Value>"));
static_assert(is_object_v<_Kty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");
static_assert(is_object_v<_Ty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");

using _Mybase = _Tree<_Tmap_traits<_Kty, _Ty, _Pr, _Alloc, true>>;
using key_type = _Kty;
Expand Down
4 changes: 0 additions & 4 deletions stl/inc/unordered_map
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public:
_MISMATCHED_ALLOCATOR_MESSAGE("unordered_map<Key, Value, Hasher, Eq, Allocator>", "pair<const Key, Value>"));
static_assert(is_object_v<_Kty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");
static_assert(is_object_v<_Ty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");

private:
using _Mytraits = _Uhash_compare<_Kty, _Hasher, _Keyeq>;
Expand Down Expand Up @@ -563,8 +561,6 @@ public:
"unordered_multimap<Key, Value, Hasher, Eq, Allocator>", "pair<const Key, Value>"));
static_assert(is_object_v<_Kty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");
static_assert(is_object_v<_Ty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");

private:
using _Mytraits = _Uhash_compare<_Kty, _Hasher, _Keyeq>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,17 @@ void assert_container() {
check_all_specific_requirements<Tag>();
}

// MapLike<K, V&> is squirrelly, but appears to be permitted.
template <template <class...> class MapLike>
void check_reference_as_mapped_type() {
double dbl = 3.14;

MapLike<int, double&> ml;
ml.emplace(10, dbl);

STATIC_ASSERT(std::is_same_v<decltype(ml.find(10)->second), double&>);
}

void assert_all() {
assert_container<tag_deque>();
assert_container<tag_forward_list>();
Expand All @@ -3063,4 +3074,9 @@ void assert_all() {
assert_container<tag_unordered_multimap>();
assert_container<tag_unordered_multiset>();
assert_container<tag_unordered_set>();

check_reference_as_mapped_type<std::map>();
check_reference_as_mapped_type<std::multimap>();
check_reference_as_mapped_type<std::unordered_map>();
check_reference_as_mapped_type<std::unordered_multimap>();
}

0 comments on commit 0a2d59e

Please sign in to comment.