redesigned init_type/value_type machinery

This commit is contained in:
joaquintides
2022-10-06 17:50:30 +02:00
parent 2cf9d5ac4c
commit d02b12c9a1
3 changed files with 25 additions and 26 deletions

View File

@ -829,6 +829,11 @@ table:empty_value<Hash,0>,empty_value<Pred,1>,empty_value<Allocator,1>
public:
using key_type=typename type_policy::key_type;
using init_type=typename type_policy::init_type;
private:
using moved_type=typename type_policy::moved_type;
public:
using value_type=typename type_policy::value_type;
private:
@ -995,7 +1000,7 @@ public:
*/
x.for_all_elements([this](value_type* p){
unchecked_insert(std::move(*p));
unchecked_insert(type_policy::move(*p));
});
}
BOOST_CATCH(...){
@ -1221,6 +1226,17 @@ private:
return type_policy::extract(x);
}
template<
bool dependent_value=false,
typename std::enable_if<
has_different_init_type||dependent_value>::type* =nullptr
>
static inline auto key_from(const moved_type& x)
->decltype(type_policy::extract(x))
{
return type_policy::extract(x);
}
static inline auto key_from(const value_type& x)
->decltype(type_policy::extract(x))
{
@ -1361,9 +1377,8 @@ private:
void nosize_transfer_element(value_type* p,const arrays_type& arrays_)
{
auto hash=h()(key_from(*p));
type_policy::move_parts_to(
*p,
bind_unchecked_emplace_at{this,arrays_,position_for(hash,arrays_),hash});
nosize_unchecked_emplace_at(
arrays_,position_for(hash,arrays_),hash,type_policy::move(*p));
destroy_element(p);
}
@ -1429,21 +1444,6 @@ private:
}
#endif
struct bind_unchecked_emplace_at
{
template<typename... Args>
iterator operator()(Args&&... args)const
{
return this_->nosize_unchecked_emplace_at(
arrays,pos0,hash,std::forward<Args>(args)...);
}
table* this_;
const arrays_type& arrays;
std::size_t pos0;
std::size_t hash;
};
template<typename F>
void for_all_elements(F f)const
{

View File

@ -30,14 +30,16 @@ namespace boost {
{
using key_type = Key;
using init_type = std::pair<Key, T>;
using moved_type = std::pair<Key&&, T&&>;
using value_type = std::pair<Key const, T>;
static Key const& extract(init_type const& kv) { return kv.first; }
static Key const& extract(value_type const& kv) { return kv.first; }
static Key const& extract(moved_type const& kv) { return kv.first; }
template <typename F> static void move_parts_to(value_type& x, F f)
static moved_type move(value_type& x)
{
// TODO: we probably need to launder here
f(std::move(const_cast<Key&>(x.first)), std::move(x.second));
return {std::move(const_cast<Key&>(x.first)), std::move(x.second)};
}
};

View File

@ -30,13 +30,10 @@ namespace boost {
{
using key_type = Key;
using init_type = Key;
using moved_type = Key;
using value_type = Key;
static Key const& extract(value_type const& key) { return key; }
template <typename F> static void move_parts_to(value_type& x, F f)
{
f(std::move(x));
}
static Key&& move(value_type& x) { return std::move(x); }
};
using table_type = detail::foa::table<set_types, Hash, KeyEqual,