Skip to content

Commit 41e9168

Browse files
committed
meta: internal change
1 parent 1650d05 commit 41e9168

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ TODO:
3131
* allow passing arguments to meta setter/getter (we can fallback on meta invoke probably)
3232
* FetchContent_Populate -> FetchContent_MakeAvailable warnings
3333
* doc: IMPLICIT_DIR_DOCS for dir docs or \dir
34-
* meta non-const allow_cast overloads: (const int &) to (int &) is not allowed, but (const int &) to (double &) is allowed
34+
* meta non-const allow_cast overloads: (const int &) to (int &) is not allowed, but (const int &) to (double &) is allowed (support only for convertibles)
3535
* improve non-const allow cast with in-place switch

src/entt/meta/meta.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,12 @@ class meta_any {
526526
*/
527527
template<typename Type>
528528
[[nodiscard]] bool allow_cast() {
529-
// also support early return for performance reasons
530-
return (((node.info != nullptr) && (*node.info == entt::type_id<Type>())) || allow_cast(meta_type{*ctx, internal::resolve<std::remove_cv_t<std::remove_reference_t<Type>>>(internal::meta_context::from(*ctx))}))
531-
&& (!(std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>) || storage.data() != nullptr);
529+
if constexpr(std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>) {
530+
return allow_cast<const std::remove_reference_t<Type> &>() && (storage.data() != nullptr);
531+
} else {
532+
// also support early return for performance reasons
533+
return ((node.info != nullptr) && (*node.info == entt::type_id<Type>())) || allow_cast(meta_type{*ctx, internal::resolve<std::remove_cv_t<std::remove_reference_t<Type>>>(internal::meta_context::from(*ctx))});
534+
}
532535
}
533536

534537
/*! @copydoc any::emplace */

0 commit comments

Comments
 (0)