From 357eed44a105e39e67259676386236376d0d31a1 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Mon, 3 Oct 2022 19:36:53 +0200 Subject: [PATCH] replaced homegrown ebo_base with boost::empty_value --- include/boost/unordered/detail/foa.hpp | 63 +++++++++----------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 3da7554f..7a53c38f 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -14,11 +14,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -824,29 +824,6 @@ using table_arrays=typename std::conditional< aligned_table_arrays, subaligned_table_arrays>::type; -template -struct ebo_base -{ - T& get(){return x;} - const T& get()const{return x;} - - T x; -}; - -template -struct ebo_base< - I,T, - typename std::enable_if< - std::is_class::value&&!boost::is_final::value>::type ->:T -{ - template - ebo_base(Arg&& x):T{std::forward(x)}{} - - T& get(){return *this;} - const T& get()const{return *this;} -}; - #if defined(BOOST_GCC) /* GCC's -Wshadow triggers at scenarios like this: * @@ -862,7 +839,7 @@ struct ebo_base< * * This makes shadowing warnings unavoidable in general when a class template * derives from user-provided classes, as is the case with table and - * ebo_base's below. + * empty_value's below. */ #pragma GCC diagnostic push @@ -876,11 +853,11 @@ class __declspec(empty_bases) /* activate EBO with multiple inheritance */ #endif -table:ebo_base<0,Hash>,ebo_base<1,Pred>,ebo_base<2,Allocator> +table:empty_value,empty_value,empty_value { - using hash_base=ebo_base<0,Hash>; - using pred_base=ebo_base<1,Pred>; - using allocator_base=ebo_base<2,Allocator>; + using hash_base=empty_value; + using pred_base=empty_value; + using allocator_base=empty_value; using type_policy=TypePolicy; using group_type=group15; static constexpr auto N=group_type::N; @@ -915,8 +892,9 @@ public: table( std::size_t n=0,const Hash& h_=Hash(),const Pred& pred_=Pred(), const Allocator& al_=Allocator()): - hash_base{h_},pred_base{pred_},allocator_base{al_}, - size_{0},arrays{new_arrays(n)},ml{max_load()} + hash_base{empty_init,h_},pred_base{empty_init,pred_}, + allocator_base{empty_init,al_},size_{0},arrays{new_arrays(n)}, + ml{max_load()} {} table(const table& x): @@ -928,8 +906,10 @@ public: std::is_nothrow_move_constructible::value&& std::is_nothrow_move_constructible::value): // TODO verify if we should copy or move copy hash, pred and al - hash_base{std::move(x.h())},pred_base{std::move(x.pred())}, - allocator_base{std::move(x.al())},size_{x.size_},arrays{x.arrays},ml{x.ml} + hash_base{empty_init,std::move(x.h())}, + pred_base{empty_init,std::move(x.pred())}, + allocator_base{empty_init,std::move(x.al())}, + size_{x.size_},arrays{x.arrays},ml{x.ml} { x.size_=0; x.arrays=x.new_arrays(0); @@ -937,7 +917,8 @@ public: } table(const table& x,const Allocator& al_): - hash_base{x.h()},pred_base{x.pred()},allocator_base{al_},size_{0}, + hash_base{empty_init,x.h()},pred_base{empty_init,x.pred()}, + allocator_base{empty_init,al_},size_{0}, arrays{ new_arrays(std::size_t(std::ceil(static_cast(x.size())/mlf)))}, ml{max_load()} @@ -1210,14 +1191,12 @@ public: private: using arrays_type=table_arrays; - Hash& h(){return static_cast(this)->get();} - const Hash& h()const{return static_cast(this)->get();} - Pred& pred(){return static_cast(this)->get();} - const Pred& pred()const - {return static_cast(this)->get();} - Allocator& al(){return static_cast(this)->get();} - const Allocator& al()const - {return static_cast(this)->get();} + Hash& h(){return hash_base::get();} + const Hash& h()const{return hash_base::get();} + Pred& pred(){return pred_base::get();} + const Pred& pred()const{return pred_base::get();} + Allocator& al(){return allocator_base::get();} + const Allocator& al()const{return allocator_base::get();} arrays_type new_arrays(std::size_t n) {