From 57ea45cb8fcff7a76ec20e552b2363e262c528b5 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Wed, 12 Oct 2022 10:31:52 +0200 Subject: [PATCH] overloaded for_all_elements --- include/boost/unordered/detail/foa.hpp | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 63d5e827..8d5a258b 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1175,20 +1175,10 @@ public: void clear()noexcept { - auto pg=arrays.groups; - auto p=arrays.elements; - if(p){ - for(std::size_t pos=0,last=arrays.groups_size_mask+1; - pos!=last;++pos,++pg,p+=N){ - auto mask=pg->match_really_occupied(); - while(mask){ - auto n=unchecked_countr_zero(mask); - destroy_element(p+n); - pg->reset(n); - mask&=mask-1; - } - } - } + for_all_elements([&,this](group_type* pg,unsigned int n,value_type* p){ + destroy_element(p); + pg->reset(n); + }); size_=0; } @@ -1525,7 +1515,16 @@ private: } template - static void for_all_elements(const arrays_type& arrays_,F f) + static auto for_all_elements(const arrays_type& arrays_,F f) + ->decltype(f(nullptr),void()) + { + for_all_elements( + arrays_,[=](group_type*,unsigned int,value_type* p){return f(p);}); + } + + template + static auto for_all_elements(const arrays_type& arrays_,F f) + ->decltype(f(nullptr,0,nullptr),void()) { auto pg=arrays_.groups; auto p=arrays_.elements; @@ -1534,7 +1533,8 @@ private: pos!=last;++pos,++pg,p+=N){ auto mask=pg->match_really_occupied(); while(mask){ - f(p+unchecked_countr_zero(mask)); + auto n=unchecked_countr_zero(mask); + f(pg,n,p+n); mask&=mask-1; } }