meta: drop friendship between meta_any and meta_type

This commit is contained in:
Michele Caini
2023-07-31 13:56:54 +02:00
parent 735e0af91a
commit 29510716bb
3 changed files with 8 additions and 9 deletions

1
TODO
View File

@@ -17,6 +17,7 @@ TODO (high prio):
* view with entity storage: begin/end should return filtered iterators
* update view doc: single vs multi type views are no longer a thing actually
* meta container: add value type to resize
* meta: merge deep search functions if possible
* ===> TEST: review view tests after the last changes
WIP:

View File

@@ -1099,8 +1099,6 @@ private:
/*! @brief Opaque wrapper for types. */
class meta_type {
friend class meta_any;
template<typename Func>
[[nodiscard]] auto lookup(meta_any *const args, const typename internal::meta_type_node::size_type sz, [[maybe_unused]] bool constness, Func next) const {
decltype(next()) candidate = nullptr;
@@ -1343,7 +1341,7 @@ public:
* @return True if the conversion is allowed, false otherwise.
*/
[[nodiscard]] bool can_convert(const meta_type &other) const noexcept {
return internal::try_convert(internal::meta_context::from(*ctx), node, other.node, nullptr, [](const void *, auto &&...args) { return ((args, 1) + ... + 0u); });
return internal::try_convert(internal::meta_context::from(*ctx), node, other.info(), other.is_arithmetic() || other.is_enum(), nullptr, [](const void *, auto &&...args) { return ((void(args), 1) + ... + 0u); });
}
/**
@@ -1623,7 +1621,7 @@ bool meta_any::set(const id_type id, Type &&value) {
}
[[nodiscard]] inline meta_any meta_any::allow_cast(const meta_type &type) const {
return internal::try_convert(internal::meta_context::from(*ctx), node, type.node, data(), [this, &type](const void *instance, auto &&...args) {
return internal::try_convert(internal::meta_context::from(*ctx), node, type.info(), type.is_arithmetic() || type.is_enum(), data(), [this, &type](const void *instance, auto &&...args) {
if constexpr((std::is_same_v<std::remove_const_t<std::remove_reference_t<decltype(args)>>, internal::meta_type_node> || ...)) {
return (args.from_void(*ctx, nullptr, instance), ...);
} else if constexpr((std::is_same_v<std::remove_const_t<std::remove_reference_t<decltype(args)>>, internal::meta_conv_node> || ...)) {

View File

@@ -160,24 +160,24 @@ template<typename... Args>
}
template<typename Func>
[[nodiscard]] inline auto try_convert(const meta_context &context, const meta_type_node &from, const meta_type_node &to, const void *instance, Func func) {
if(from.info && *from.info == *to.info) {
[[nodiscard]] inline auto try_convert(const meta_context &context, const meta_type_node &from, const type_info &to, const bool arithmetic_or_enum, const void *instance, Func func) {
if(from.info && *from.info == to) {
return func(instance, from);
}
if(from.details) {
if(auto it = from.details->conv.find(to.info->hash()); it != from.details->conv.cend()) {
if(auto it = from.details->conv.find(to.hash()); it != from.details->conv.cend()) {
return func(instance, it->second);
}
for(auto &&curr: from.details->base) {
if(auto other = try_convert(context, curr.second.type(context), to, curr.second.cast(instance), func); other) {
if(auto other = try_convert(context, curr.second.type(context), to, arithmetic_or_enum, curr.second.cast(instance), func); other) {
return other;
}
}
}
if(from.conversion_helper && static_cast<bool>(to.traits & (meta_traits::is_arithmetic | meta_traits::is_enum))) {
if(from.conversion_helper && arithmetic_or_enum) {
return func(instance, from.conversion_helper);
}