mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 03:17:15 +02:00
Add transparent at()
This commit is contained in:
@ -473,6 +473,34 @@ namespace boost {
|
||||
std::out_of_range("key was not found in unordered_flat_map"));
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
mapped_type&>::type
|
||||
at(K&& key)
|
||||
{
|
||||
auto pos = table_.find(std::forward<K>(key));
|
||||
if (pos != table_.end()) {
|
||||
return pos->second;
|
||||
}
|
||||
boost::throw_exception(
|
||||
std::out_of_range("key was not found in unordered_flat_map"));
|
||||
}
|
||||
|
||||
template <class K>
|
||||
typename std::enable_if<
|
||||
boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
|
||||
mapped_type const&>::type
|
||||
at(K&& key) const
|
||||
{
|
||||
auto pos = table_.find(std::forward<K>(key));
|
||||
if (pos != table_.end()) {
|
||||
return pos->second;
|
||||
}
|
||||
boost::throw_exception(
|
||||
std::out_of_range("key was not found in unordered_flat_map"));
|
||||
}
|
||||
|
||||
BOOST_FORCEINLINE mapped_type& operator[](key_type const& key)
|
||||
{
|
||||
return table_.try_emplace(key).first->second;
|
||||
|
@ -973,13 +973,23 @@ 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;
|
||||
|
||||
template <class Key>
|
||||
typename boost::enable_if_c<detail::are_transparent<Key, H, P>::value,
|
||||
mapped_type&>::type at(BOOST_FWD_REF(Key) k);
|
||||
|
||||
template <class Key>
|
||||
typename boost::enable_if_c<detail::are_transparent<Key, H, P>::value,
|
||||
mapped_type const&>::type at(BOOST_FWD_REF(Key) k) const;
|
||||
|
||||
// bucket interface
|
||||
|
||||
size_type bucket_count() const BOOST_NOEXCEPT
|
||||
@ -2260,6 +2270,42 @@ namespace boost {
|
||||
std::out_of_range("Unable to find key in unordered_map."));
|
||||
}
|
||||
|
||||
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>::at(BOOST_FWD_REF(Key) k)
|
||||
{
|
||||
typedef typename table::node_pointer node_pointer;
|
||||
|
||||
if (table_.size_) {
|
||||
node_pointer p = table_.find_node(boost::forward<Key>(k));
|
||||
if (p)
|
||||
return p->value().second;
|
||||
}
|
||||
|
||||
boost::throw_exception(
|
||||
std::out_of_range("Unable to find key in unordered_map."));
|
||||
}
|
||||
|
||||
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 const&>::type
|
||||
unordered_map<K, T, H, P, A>::at(BOOST_FWD_REF(Key) k) const
|
||||
{
|
||||
typedef typename table::node_pointer node_pointer;
|
||||
|
||||
if (table_.size_) {
|
||||
node_pointer p = table_.find_node(boost::forward<Key>(k));
|
||||
if (p)
|
||||
return p->value().second;
|
||||
}
|
||||
|
||||
boost::throw_exception(
|
||||
std::out_of_range("Unable to find key in unordered_map."));
|
||||
}
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
typename unordered_map<K, T, H, P, A>::size_type
|
||||
unordered_map<K, T, H, P, A>::bucket_size(size_type n) const
|
||||
|
Reference in New Issue
Block a user