From 16099478db5dd9276f0ea5a5d0072b8b969eebd8 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Tue, 31 Jan 2023 10:31:52 -0800 Subject: [PATCH] Clean up implementation of emplace_dispatch(false_type) --- include/boost/unordered/detail/foa.hpp | 54 +++++++++++--------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 802ab66f..5731cc41 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1400,37 +1400,6 @@ public: std::forward(args)...); } - template - BOOST_FORCEINLINE std::pair emplace_dispatch( - std::true_type,Args&&... args - ) { - using emplace_type_t = emplace_type; - return emplace_impl(emplace_type_t(std::forward(args)...)); - } - - template - BOOST_FORCEINLINE std::pair emplace_dispatch( - std::false_type,Args&&... args - ) { - struct guard { - table& t; - element_type& x; - bool destroy; - ~guard(){ - if(destroy) { - type_policy::destroy(t.al(),&x); - } - } - }; - - element_type x; - type_policy::construct(al(),&x,std::forward(args)...); - guard g{*this,x,true}; - auto itp=emplace_impl(type_policy::move(x)); - g.destroy=!itp.second; - return itp; - } - template BOOST_FORCEINLINE std::pair try_emplace( Key&& x,Args&&... args) @@ -1887,6 +1856,29 @@ private: #pragma warning(pop) /* C4800 */ #endif + template + BOOST_FORCEINLINE std::pair emplace_dispatch( + std::true_type,Args&&... args + ) { + using emplace_type_t = emplace_type; + return emplace_impl(emplace_type_t(std::forward(args)...)); + } + + template + BOOST_FORCEINLINE std::pair emplace_dispatch( + std::false_type,Args&&... args + ) { + alignas(element_type) + unsigned char buf[sizeof(element_type)]; + element_type* p = reinterpret_cast(buf); + + type_policy::construct(al(),p,std::forward(args)...); + destroy_element_on_exit d{this,p}; + (void)d; + + return emplace_impl(type_policy::move(*p)); + } + template BOOST_FORCEINLINE std::pair emplace_impl(Args&&... args) {