meta: context aware internal try_cast
This commit is contained in:
@@ -340,7 +340,8 @@ public:
|
||||
*/
|
||||
template<typename Type>
|
||||
[[nodiscard]] const Type *try_cast() const {
|
||||
return static_cast<const Type *>(internal::try_cast(node, internal::resolve_TODO<std::remove_cv_t<Type>>(), data()));
|
||||
auto &&context_TODO = internal::meta_context::from(locator<meta_ctx>::value_or());
|
||||
return static_cast<const Type *>(internal::try_cast(node, internal::resolve<std::remove_cv_t<Type>>(context_TODO), data(), context_TODO));
|
||||
}
|
||||
|
||||
/*! @copydoc try_cast */
|
||||
@@ -349,7 +350,8 @@ public:
|
||||
if constexpr(std::is_const_v<Type>) {
|
||||
return std::as_const(*this).try_cast<std::remove_const_t<Type>>();
|
||||
} else {
|
||||
return static_cast<Type *>(const_cast<void *>(internal::try_cast(node, internal::resolve_TODO<Type>(), data())));
|
||||
auto &&context_TODO = internal::meta_context::from(locator<meta_ctx>::value_or());
|
||||
return static_cast<Type *>(const_cast<void *>(internal::try_cast(node, internal::resolve<Type>(context_TODO), data(), context_TODO)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,16 +148,14 @@ template<typename... Args>
|
||||
return value(context);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const void *try_cast(const meta_type_node &from, const meta_type_node &to, const void *instance) noexcept {
|
||||
[[nodiscard]] inline const void *try_cast(const meta_type_node &from, const meta_type_node &to, const void *instance, const meta_context &context) noexcept {
|
||||
if(from.info && to.info && *from.info == *to.info) {
|
||||
return instance;
|
||||
}
|
||||
|
||||
if(from.details) {
|
||||
auto &&context_TODO = meta_context::from(locator<meta_ctx>::value_or());
|
||||
|
||||
for(auto &&curr: from.details->base) {
|
||||
if(const void *elem = try_cast(curr.second.type(context_TODO), to, curr.second.cast(instance)); elem) {
|
||||
if(const void *elem = try_cast(curr.second.type(context), to, curr.second.cast(instance), context); elem) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user