From c1d5902911425f5760dfc7d211c6e738b5c26b6f Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Thu, 20 Oct 2022 08:43:42 -0700 Subject: [PATCH] Remove unnecessary value_type conversion by expanding overloads for value_from() --- include/boost/unordered/detail/foa.hpp | 19 ++++++++++++++++++- .../boost/unordered/unordered_flat_map.hpp | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 9dae609f..3a224714 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1499,13 +1499,30 @@ private: template< typename T, - typename std::enable_if::value>::type* =nullptr + typename Ty=typename std::decay::type, + typename std::enable_if< + !is_init_or_value_type::value&& + std::is_convertible::value + >::type* =nullptr > static inline init_type value_from(T&& x) { return std::forward(x); } + template< + typename T, + typename Ty=typename std::decay::type, + typename std::enable_if< + !is_init_or_value_type::value&& + !std::is_convertible::value + >::type* =nullptr + > + static inline value_type value_from(T&& x) + { + return std::forward(x); + } + template static inline auto key_from(const T& x) ->decltype(type_policy::extract(x)) diff --git a/include/boost/unordered/unordered_flat_map.hpp b/include/boost/unordered/unordered_flat_map.hpp index ea90c7e6..bcaa8dce 100644 --- a/include/boost/unordered/unordered_flat_map.hpp +++ b/include/boost/unordered/unordered_flat_map.hpp @@ -239,7 +239,7 @@ namespace boost { void insert(InputIterator first, InputIterator last) { for (auto pos = first; pos != last; ++pos) { - table_.insert(value_type(*pos)); + table_.insert(*pos); } }