Cleanup: simplify getting value of generic ValueOrField
This commit is contained in:
parent
e756b0fea0
commit
f7e9bc65ab
|
@ -17,7 +17,6 @@ class ValueOrFieldCPPType {
|
|||
private:
|
||||
void (*construct_from_value_)(void *dst, const void *value);
|
||||
void (*construct_from_field_)(void *dst, GField field);
|
||||
const void *(*get_value_ptr_)(const void *value_or_field);
|
||||
const GField *(*get_field_ptr_)(const void *value_or_field);
|
||||
bool (*is_field_)(const void *value_or_field);
|
||||
GField (*as_field_)(const void *value_or_field);
|
||||
|
@ -42,13 +41,14 @@ class ValueOrFieldCPPType {
|
|||
|
||||
const void *get_value_ptr(const void *value_or_field) const
|
||||
{
|
||||
return get_value_ptr_(value_or_field);
|
||||
static_assert(offsetof(ValueOrField<int>, value) == 0);
|
||||
return value_or_field;
|
||||
}
|
||||
|
||||
void *get_value_ptr(void *value_or_field) const
|
||||
{
|
||||
/* Use `const_cast` to avoid duplicating the callback for the non-const case. */
|
||||
return const_cast<void *>(get_value_ptr_(value_or_field));
|
||||
static_assert(offsetof(ValueOrField<int>, value) == 0);
|
||||
return value_or_field;
|
||||
}
|
||||
|
||||
const GField *get_field_ptr(const void *value_or_field) const
|
||||
|
|
|
@ -17,9 +17,6 @@ inline ValueOrFieldCPPType::ValueOrFieldCPPType(TypeTag<ValueType> /*value_type*
|
|||
construct_from_field_ = [](void *dst, GField field) {
|
||||
new (dst) ValueOrField<T>(Field<T>(std::move(field)));
|
||||
};
|
||||
get_value_ptr_ = [](const void *value_or_field) {
|
||||
return (const void *)&((ValueOrField<T> *)value_or_field)->value;
|
||||
};
|
||||
get_field_ptr_ = [](const void *value_or_field) -> const GField * {
|
||||
return &((ValueOrField<T> *)value_or_field)->field;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue