mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 03:17:15 +02:00
replaced homegrown ebo_base with boost::empty_value
This commit is contained in:
@ -14,11 +14,11 @@
|
|||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/core/bit.hpp>
|
#include <boost/core/bit.hpp>
|
||||||
|
#include <boost/core/empty_value.hpp>
|
||||||
#include <boost/core/no_exceptions_support.hpp>
|
#include <boost/core/no_exceptions_support.hpp>
|
||||||
#include <boost/core/pointer_traits.hpp>
|
#include <boost/core/pointer_traits.hpp>
|
||||||
#include <boost/cstdint.hpp>
|
#include <boost/cstdint.hpp>
|
||||||
#include <boost/predef.h>
|
#include <boost/predef.h>
|
||||||
#include <boost/type_traits/is_final.hpp>
|
|
||||||
#include <boost/type_traits/is_nothrow_swappable.hpp>
|
#include <boost/type_traits/is_nothrow_swappable.hpp>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -824,29 +824,6 @@ using table_arrays=typename std::conditional<
|
|||||||
aligned_table_arrays<Value,Group,SizePolicy>,
|
aligned_table_arrays<Value,Group,SizePolicy>,
|
||||||
subaligned_table_arrays<Value,Group,SizePolicy>>::type;
|
subaligned_table_arrays<Value,Group,SizePolicy>>::type;
|
||||||
|
|
||||||
template<std::size_t I,typename T,typename=void>
|
|
||||||
struct ebo_base
|
|
||||||
{
|
|
||||||
T& get(){return x;}
|
|
||||||
const T& get()const{return x;}
|
|
||||||
|
|
||||||
T x;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<std::size_t I,typename T>
|
|
||||||
struct ebo_base<
|
|
||||||
I,T,
|
|
||||||
typename std::enable_if<
|
|
||||||
std::is_class<T>::value&&!boost::is_final<T>::value>::type
|
|
||||||
>:T
|
|
||||||
{
|
|
||||||
template<typename Arg>
|
|
||||||
ebo_base(Arg&& x):T{std::forward<Arg>(x)}{}
|
|
||||||
|
|
||||||
T& get(){return *this;}
|
|
||||||
const T& get()const{return *this;}
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(BOOST_GCC)
|
#if defined(BOOST_GCC)
|
||||||
/* GCC's -Wshadow triggers at scenarios like this:
|
/* 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
|
* This makes shadowing warnings unavoidable in general when a class template
|
||||||
* derives from user-provided classes, as is the case with table and
|
* derives from user-provided classes, as is the case with table and
|
||||||
* ebo_base's below.
|
* empty_value's below.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
@ -876,11 +853,11 @@ class
|
|||||||
__declspec(empty_bases) /* activate EBO with multiple inheritance */
|
__declspec(empty_bases) /* activate EBO with multiple inheritance */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
table:ebo_base<0,Hash>,ebo_base<1,Pred>,ebo_base<2,Allocator>
|
table:empty_value<Hash,0>,empty_value<Pred,1>,empty_value<Allocator,1>
|
||||||
{
|
{
|
||||||
using hash_base=ebo_base<0,Hash>;
|
using hash_base=empty_value<Hash,0>;
|
||||||
using pred_base=ebo_base<1,Pred>;
|
using pred_base=empty_value<Pred,1>;
|
||||||
using allocator_base=ebo_base<2,Allocator>;
|
using allocator_base=empty_value<Allocator,1>;
|
||||||
using type_policy=TypePolicy;
|
using type_policy=TypePolicy;
|
||||||
using group_type=group15;
|
using group_type=group15;
|
||||||
static constexpr auto N=group_type::N;
|
static constexpr auto N=group_type::N;
|
||||||
@ -915,8 +892,9 @@ public:
|
|||||||
table(
|
table(
|
||||||
std::size_t n=0,const Hash& h_=Hash(),const Pred& pred_=Pred(),
|
std::size_t n=0,const Hash& h_=Hash(),const Pred& pred_=Pred(),
|
||||||
const Allocator& al_=Allocator()):
|
const Allocator& al_=Allocator()):
|
||||||
hash_base{h_},pred_base{pred_},allocator_base{al_},
|
hash_base{empty_init,h_},pred_base{empty_init,pred_},
|
||||||
size_{0},arrays{new_arrays(n)},ml{max_load()}
|
allocator_base{empty_init,al_},size_{0},arrays{new_arrays(n)},
|
||||||
|
ml{max_load()}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
table(const table& x):
|
table(const table& x):
|
||||||
@ -928,8 +906,10 @@ public:
|
|||||||
std::is_nothrow_move_constructible<Pred>::value&&
|
std::is_nothrow_move_constructible<Pred>::value&&
|
||||||
std::is_nothrow_move_constructible<Allocator>::value):
|
std::is_nothrow_move_constructible<Allocator>::value):
|
||||||
// TODO verify if we should copy or move copy hash, pred and al
|
// 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())},
|
hash_base{empty_init,std::move(x.h())},
|
||||||
allocator_base{std::move(x.al())},size_{x.size_},arrays{x.arrays},ml{x.ml}
|
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.size_=0;
|
||||||
x.arrays=x.new_arrays(0);
|
x.arrays=x.new_arrays(0);
|
||||||
@ -937,7 +917,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
table(const table& x,const Allocator& al_):
|
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{
|
arrays{
|
||||||
new_arrays(std::size_t(std::ceil(static_cast<float>(x.size())/mlf)))},
|
new_arrays(std::size_t(std::ceil(static_cast<float>(x.size())/mlf)))},
|
||||||
ml{max_load()}
|
ml{max_load()}
|
||||||
@ -1210,14 +1191,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
using arrays_type=table_arrays<value_type,group_type,size_policy>;
|
using arrays_type=table_arrays<value_type,group_type,size_policy>;
|
||||||
|
|
||||||
Hash& h(){return static_cast<hash_base*>(this)->get();}
|
Hash& h(){return hash_base::get();}
|
||||||
const Hash& h()const{return static_cast<const hash_base*>(this)->get();}
|
const Hash& h()const{return hash_base::get();}
|
||||||
Pred& pred(){return static_cast<pred_base*>(this)->get();}
|
Pred& pred(){return pred_base::get();}
|
||||||
const Pred& pred()const
|
const Pred& pred()const{return pred_base::get();}
|
||||||
{return static_cast<const pred_base*>(this)->get();}
|
Allocator& al(){return allocator_base::get();}
|
||||||
Allocator& al(){return static_cast<allocator_base*>(this)->get();}
|
const Allocator& al()const{return allocator_base::get();}
|
||||||
const Allocator& al()const
|
|
||||||
{return static_cast<const allocator_base*>(this)->get();}
|
|
||||||
|
|
||||||
arrays_type new_arrays(std::size_t n)
|
arrays_type new_arrays(std::size_t n)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user