From 7eeb828980aaddbd592c4c8d6339e96589b60913 Mon Sep 17 00:00:00 2001 From: skypjack Date: Tue, 4 Nov 2025 14:06:53 +0100 Subject: [PATCH] meta: further refine typed allow_cast --- TODO | 2 +- src/entt/meta/meta.hpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 29524c361..56d2f50ce 100644 --- a/TODO +++ b/TODO @@ -34,6 +34,6 @@ TODO: * finish the imgui viewer/editor! * introduce compile-time flag to skip dll-only checks in basic_any * archetype-like a-là EnTT support (see my own notes) -* meta_any typed try_cast/allow_cast should not rely on non-typed ones for perf reasons +* meta_any refine allow_cast implementations * meta: conversion_helper machinery has lot of room for improvements * meta_factory: add a replace flag to traits to get around the |-only mechanism diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index fd49a35fe..6b8577908 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -520,7 +520,17 @@ public: if constexpr(std::is_reference_v && !std::is_const_v>) { return allow_cast &>() && (storage.data() != nullptr); } else { - return storage.has_value>>() || allow_cast(meta_type{*ctx, internal::resolve>>(internal::meta_context::from(*ctx))}); + if(storage.has_value>>()) { + return true; + } else if(auto other = std::as_const(*this).allow_cast>>(); other) { + if(other.storage.owner()) { + std::swap(*this, other); + } + + return true; + } + + return false; } }