diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index 7b2ff6fc..f40d03d4 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -729,6 +729,7 @@ template class unordered_map const key_type&) const; mapped_type& operator[](const key_type&); + mapped_type& operator[](BOOST_RV_REF(key_type)); mapped_type& at(const key_type&); mapped_type const& at(const key_type&) const; @@ -1627,6 +1628,13 @@ typename unordered_map::mapped_type& return table_.try_emplace_impl(k).first->second; } +template +typename unordered_map::mapped_type& + unordered_map::operator[](BOOST_RV_REF(key_type) k) +{ + return table_.try_emplace_impl(boost::move(k)).first->second; +} + template typename unordered_map::mapped_type& unordered_map::at(const key_type& k) diff --git a/test/unordered/compile_tests.hpp b/test/unordered/compile_tests.hpp index c676f2d5..12759c16 100644 --- a/test/unordered/compile_tests.hpp +++ b/test/unordered/compile_tests.hpp @@ -422,6 +422,7 @@ void unordered_map_functions(X&, Key const& k, T const& v) X a; test::check_return_type::equals_ref(a[k]); + test::check_return_type::equals_ref(a[rvalue(k)]); test::check_return_type::equals_ref(a.at(k)); test::check_return_type >::equals( a.try_emplace(k, v));