From 74ca1e50f3eabc0997c0b7504d828a7cd92822d7 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Fri, 7 Oct 2022 11:27:54 +0200 Subject: [PATCH] return one lambda expression back in place (related to f1eb5d2106d666bb7fd620430e4ce48c257605e2) --- include/boost/unordered/detail/foa.hpp | 41 +++++++++++++------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 33c53c27..39da1f26 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -979,35 +979,19 @@ public: static constexpr auto pocma= alloc_traits::propagate_on_container_move_assignment::value; - /* Avoid using nested lambdas with a `this` capture as it seems to trigger + /* Avoid using nested lambdas with a `this` capture as it seems to trigger * a bug in GCC: * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947 * * Rather than directly attempting to manipulate the visibility of the * table class, it's easier to work around the bug by simply un-nesting the - * lambdas + * lambda. */ + auto const move_element=[this](value_type* p){ unchecked_insert(std::move(*p)); }; - auto const elementwise_move=[&,this]{ - reserve(x.size()); - BOOST_TRY{ - /* This works because subsequent x.clear() does not depend on the - * elements' values. - */ - - x.for_all_elements(move_element); - } - BOOST_CATCH(...){ - x.clear(); - BOOST_RETHROW - } - BOOST_CATCH_END - x.clear(); - }; - if(this!=&x){ clear(); h()=std::move(x.h()); @@ -1020,12 +1004,27 @@ public: swap(arrays,x.arrays); swap(ml,x.ml); } - else if_constexpr( + else if_constexpr([&,this]{ /* The check above is redundant: we're setting up a compile-time * barrier so that the compiler is convinced we're not throwing * under noexcept(true) conditions. */ - elementwise_move); + + reserve(x.size()); + BOOST_TRY{ + /* This works because subsequent x.clear() does not depend on the + * elements' values. + */ + + x.for_all_elements(move_element); + } + BOOST_CATCH(...){ + x.clear(); + BOOST_RETHROW + } + BOOST_CATCH_END + x.clear(); + }); } return *this; }