diff --git a/include/boost/unordered/unordered_flat_map.hpp b/include/boost/unordered/unordered_flat_map.hpp index d7f4e6e7..16d4f3bd 100644 --- a/include/boost/unordered/unordered_flat_map.hpp +++ b/include/boost/unordered/unordered_flat_map.hpp @@ -473,6 +473,34 @@ namespace boost { std::out_of_range("key was not found in unordered_flat_map")); } + template + typename std::enable_if< + boost::unordered::detail::are_transparent::value, + mapped_type&>::type + at(K&& key) + { + auto pos = table_.find(std::forward(key)); + if (pos != table_.end()) { + return pos->second; + } + boost::throw_exception( + std::out_of_range("key was not found in unordered_flat_map")); + } + + template + typename std::enable_if< + boost::unordered::detail::are_transparent::value, + mapped_type const&>::type + at(K&& key) const + { + auto pos = table_.find(std::forward(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; diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index 315da4cc..849adefa 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -973,13 +973,23 @@ namespace boost { mapped_type& operator[](const key_type&); mapped_type& operator[](BOOST_RV_REF(key_type)); + template typename boost::enable_if_c::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 + typename boost::enable_if_c::value, + mapped_type&>::type at(BOOST_FWD_REF(Key) k); + + template + typename boost::enable_if_c::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 + template + typename boost::enable_if_c::value, + typename unordered_map::mapped_type&>::type + unordered_map::at(BOOST_FWD_REF(Key) k) + { + typedef typename table::node_pointer node_pointer; + + if (table_.size_) { + node_pointer p = table_.find_node(boost::forward(k)); + if (p) + return p->value().second; + } + + boost::throw_exception( + std::out_of_range("Unable to find key in unordered_map.")); + } + + template + template + typename boost::enable_if_c::value, + typename unordered_map::mapped_type const&>::type + unordered_map::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(k)); + if (p) + return p->value().second; + } + + boost::throw_exception( + std::out_of_range("Unable to find key in unordered_map.")); + } + template typename unordered_map::size_type unordered_map::bucket_size(size_type n) const