From aff242dbaf477c15d2def004b60f9e1a46791334 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Sat, 10 Feb 2024 11:29:45 -0600 Subject: [PATCH] Optimize emplace(k,v) for fca containers --- .../boost/unordered/detail/implementation.hpp | 23 +++++++++++++++++-- include/boost/unordered/detail/map.hpp | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/boost/unordered/detail/implementation.hpp b/include/boost/unordered/detail/implementation.hpp index 97796474..5e0d8001 100644 --- a/include/boost/unordered/detail/implementation.hpp +++ b/include/boost/unordered/detail/implementation.hpp @@ -14,6 +14,7 @@ #pragma once #endif +#include #include #include #include @@ -104,6 +105,10 @@ namespace boost { template no_key(T const&) {} }; + struct converting_key + { + }; + namespace func { template inline void ignore_unused_variable_warning(T const&) { @@ -1913,6 +1918,16 @@ namespace boost { } } + template + emplace_return emplace_unique(converting_key, K&& k, V&& v) + { + using alloc_cted = allocator_constructed; + alloc_cted key(this->node_alloc(), std::forward(k)); + return emplace_unique( + key.value(), std::move(key.value()), std::forward(v)); + } + template emplace_return try_emplace_unique(Key&& k) { std::size_t key_hash = this->hash(k); @@ -2835,9 +2850,13 @@ namespace boost { } template - static no_key extract(Arg1 const&, Arg2 const&) + static typename std::conditional< + (is_similar::value || + is_complete_and_move_constructible::value), + converting_key, no_key>::type + extract(Arg1 const&, Arg2 const&) { - return no_key(); + return {}; } template diff --git a/include/boost/unordered/detail/map.hpp b/include/boost/unordered/detail/map.hpp index ccd2508f..bba19ed1 100644 --- a/include/boost/unordered/detail/map.hpp +++ b/include/boost/unordered/detail/map.hpp @@ -18,6 +18,7 @@ namespace boost { typedef std::pair value_type; typedef H hasher; typedef P key_equal; + typedef K key_type; typedef K const const_key_type; typedef