Add transparent subscript

This commit is contained in:
Christian Mazakas
2022-11-15 15:39:15 -08:00
parent b85e17085f
commit dfbff823a9
2 changed files with 22 additions and 0 deletions

View File

@ -483,6 +483,15 @@ namespace boost {
return table_.try_emplace(std::move(key)).first->second;
}
template <class K>
typename std::enable_if<
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
mapped_type&>::type
operator[](K&& key)
{
return table_.try_emplace(std::forward<K>(key)).first->second;
}
BOOST_FORCEINLINE size_type count(key_type const& key) const
{
auto pos = table_.find(key);

View File

@ -973,6 +973,10 @@ namespace boost {
mapped_type& operator[](const key_type&);
mapped_type& operator[](BOOST_RV_REF(key_type));
template <class Key>
typename boost::enable_if_c<detail::are_transparent<Key, H, P>::value,
mapped_type&>::type
operator[](BOOST_FWD_REF(Key) k);
mapped_type& at(const key_type&);
mapped_type const& at(const key_type&) const;
@ -2215,6 +2219,15 @@ namespace boost {
return table_.try_emplace_unique(boost::move(k)).first->second;
}
template <class K, class T, class H, class P, class A>
template <class Key>
typename boost::enable_if_c<detail::are_transparent<Key, H, P>::value,
typename unordered_map<K, T, H, P, A>::mapped_type&>::type
unordered_map<K, T, H, P, A>::operator[](BOOST_FWD_REF(Key) k)
{
return table_.try_emplace_unique(boost::forward<Key>(k)).first->second;
}
template <class K, class T, class H, class P, class A>
typename unordered_map<K, T, H, P, A>::mapped_type&
unordered_map<K, T, H, P, A>::at(const key_type& k)