meta: internal changes and cleanup

This commit is contained in:
Michele Caini
2021-09-24 12:49:43 +02:00
parent 324aeba70f
commit efa98379b0
3 changed files with 13 additions and 26 deletions
+3 -3
View File
@@ -272,7 +272,7 @@ public:
static internal::meta_conv_node node{
nullptr,
internal::meta_node<conv_type>::resolve(),
[](const void *instance) -> meta_any { return forward_as_meta(static_cast<const Type *>(instance)->*Candidate)(); }
[](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast<const Type *>(instance.data())->*Candidate)(); }
// tricks clang-format
};
@@ -288,7 +288,7 @@ public:
static internal::meta_conv_node node{
nullptr,
internal::meta_node<conv_type>::resolve(),
[](const void *instance) -> meta_any { return forward_as_meta(Candidate(*static_cast<const Type *>(instance))); }
[](const meta_any &instance) -> meta_any { return forward_as_meta(Candidate(*static_cast<const Type *>(instance.data()))); }
// tricks clang-format
};
@@ -312,7 +312,7 @@ public:
static internal::meta_conv_node node{
nullptr,
internal::meta_node<std::remove_const_t<std::remove_reference_t<To>>>::resolve(),
[](const void *instance) -> meta_any { return forward_as_meta(static_cast<To>(*static_cast<const Type *>(instance))); }
[](const meta_any &instance) -> meta_any { return forward_as_meta(static_cast<To>(*static_cast<const Type *>(instance.data()))); }
// tricks clang-format
};
+9 -2
View File
@@ -971,7 +971,14 @@ class meta_type {
for(size_type next{}; next < sz && next == (direct + ext) && args[next]; ++next) {
const auto type = args[next].type();
const auto other = curr->arg(next);
type.info() == other.info() ? ++direct : (ext += internal::can_cast_or_convert(type.node, other.node));
if(const auto &info = other.info(); info == type.info()) {
++direct;
} else {
ext += internal::find_by<&node_type::base>(info, type.node)
|| internal::find_by<&node_type::conv>(info, type.node)
|| (type.node->conversion_helper && other.node->conversion_helper);
}
}
if((direct + ext) == sz) {
@@ -1381,7 +1388,7 @@ bool meta_any::set(const id_type id, Type &&value) {
if(const auto &info = type.info(); (node && *node->info == info) || internal::find_by<&internal::meta_type_node::base>(info, node)) {
return as_ref();
} else if(const auto *const conv = internal::find_by<&internal::meta_type_node::conv>(info, node); conv) {
return conv->conv(storage.data());
return conv->conv(*this);
} else if(node && node->conversion_helper && (type.is_arithmetic() || type.is_enum())) {
// exploits the fact that arithmetic types and enums are also default constructible
auto other = type.construct();
+1 -21
View File
@@ -57,7 +57,7 @@ struct meta_base_node {
struct meta_conv_node {
meta_conv_node *next;
meta_type_node *const type;
meta_any (*const conv)(const void *);
meta_any (*const conv)(const meta_any &);
};
struct meta_ctor_node {
@@ -227,26 +227,6 @@ template<auto Member, typename Type>
return nullptr;
}
[[nodiscard]] inline bool can_cast_or_convert(const internal::meta_type_node *type, const internal::meta_type_node *other) ENTT_NOEXCEPT {
if(type->info == other->info) {
return true;
}
for(const auto *curr = type->conv; curr; curr = curr->next) {
if(curr->type->info == other->info) {
return true;
}
}
for(const auto *curr = type->base; curr; curr = curr->next) {
if(can_cast_or_convert(curr->type, other)) {
return true;
}
}
return (type->conversion_helper && other->conversion_helper);
}
} // namespace internal
/**