From aaf0e402477a55dcaa0efbd1dfeba9af9d5b3d91 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Thu, 12 Jan 2023 14:25:38 -0800 Subject: [PATCH] Update unordered_node_map to be a proper copy of unordered_flat_map --- .../boost/unordered/unordered_node_map.hpp | 99 +++++++++++++++++-- 1 file changed, 90 insertions(+), 9 deletions(-) diff --git a/include/boost/unordered/unordered_node_map.hpp b/include/boost/unordered/unordered_node_map.hpp index 849469b1..46835fde 100644 --- a/include/boost/unordered/unordered_node_map.hpp +++ b/include/boost/unordered/unordered_node_map.hpp @@ -144,15 +144,13 @@ namespace boost { public: using key_type = Key; using mapped_type = T; - using value_type = std::pair; - using init_type = std::pair; + using value_type = typename map_types::value_type; + using init_type = typename map_types::init_type; using size_type = std::size_t; using difference_type = std::ptrdiff_t; using hasher = typename boost::type_identity::type; using key_equal = typename boost::type_identity::type; - using allocator_type = typename boost::type_identity< - typename boost::allocator_rebind::type>::type; + using allocator_type = typename boost::type_identity::type; using reference = value_type&; using const_reference = value_type const&; using pointer = typename boost::allocator_pointer::type; @@ -326,15 +324,14 @@ namespace boost { template BOOST_FORCEINLINE auto insert(const_iterator, Ty&& value) - -> decltype(iterator(table_.insert(std::forward(value)).first)) + -> decltype(table_.insert(std::forward(value)).first) { return table_.insert(std::forward(value)).first; } BOOST_FORCEINLINE iterator insert(const_iterator, init_type&& value) { - return table_.insert(std::move(value.first), std::move(value.second)) - .first; + return table_.insert(std::move(value)).first; } template @@ -372,6 +369,20 @@ namespace boost { return ibp; } + template + typename std::enable_if< + boost::unordered::detail::are_transparent::value, + std::pair >::type + insert_or_assign(K&& k, M&& obj) + { + auto ibp = table_.try_emplace(std::forward(k), std::forward(obj)); + if (ibp.second) { + return ibp; + } + ibp.first->second = std::forward(obj); + return ibp; + } + template iterator insert_or_assign(const_iterator, key_type const& key, M&& obj) { @@ -385,10 +396,20 @@ namespace boost { .first; } + template + typename std::enable_if< + boost::unordered::detail::are_transparent::value, + iterator>::type + insert_or_assign(const_iterator, K&& k, M&& obj) + { + return this->insert_or_assign(std::forward(k), std::forward(obj)) + .first; + } + template BOOST_FORCEINLINE std::pair emplace(Args&&... args) { - return table_.emplace(init_type(std::forward(args)...)); + return table_.emplace(std::forward(args)...); } template @@ -411,6 +432,17 @@ namespace boost { return table_.try_emplace(std::move(key), std::forward(args)...); } + template + BOOST_FORCEINLINE typename std::enable_if< + boost::unordered::detail::transparent_non_iterable::value, + std::pair >::type + try_emplace(K&& key, Args&&... args) + { + return table_.try_emplace( + std::forward(key), std::forward(args)...); + } + template BOOST_FORCEINLINE iterator try_emplace( const_iterator, key_type const& key, Args&&... args) @@ -426,6 +458,18 @@ namespace boost { .first; } + template + BOOST_FORCEINLINE typename std::enable_if< + boost::unordered::detail::transparent_non_iterable::value, + iterator>::type + try_emplace(const_iterator, K&& key, Args&&... args) + { + return table_ + .try_emplace(std::forward(key), std::forward(args)...) + .first; + } + BOOST_FORCEINLINE void erase(iterator pos) { table_.erase(pos); } BOOST_FORCEINLINE void erase(const_iterator pos) { @@ -501,6 +545,34 @@ namespace boost { std::out_of_range("key was not found in unordered_node_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_node_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_node_map")); + } + BOOST_FORCEINLINE mapped_type& operator[](key_type const& key) { return table_.try_emplace(key).first->second; @@ -511,6 +583,15 @@ namespace boost { return table_.try_emplace(std::move(key)).first->second; } + template + typename std::enable_if< + boost::unordered::detail::are_transparent::value, + mapped_type&>::type + operator[](K&& key) + { + return table_.try_emplace(std::forward(key)).first->second; + } + BOOST_FORCEINLINE size_type count(key_type const& key) const { auto pos = table_.find(key);