@@ -185,7 +185,7 @@ class meta_any {
185185 }
186186
187187 void release () {
188- if (node && node->dtor && storage. owner ()) {
188+ if (node && node->dtor && owner ()) {
189189 node->dtor (storage.data ());
190190 }
191191 }
@@ -343,35 +343,26 @@ class meta_any {
343343 */
344344 template <typename Type>
345345 [[nodiscard]] const Type *try_cast () const {
346- if (const auto &info = type_id<Type>(); node && *node->info == info) {
347- return any_cast<Type>(&storage);
348- } else if (node) {
349- for (auto *it = node->base ; it; it = it->next ) {
350- const auto as_const = it->cast (as_ref ());
351-
352- if (const Type *base = as_const.template try_cast <Type>(); base) {
353- return base;
354- }
355- }
346+ auto *self = any_cast<Type>(&storage);
347+
348+ for (auto *it = node ? node->base : nullptr ; it && !self; it = it->next ) {
349+ const auto &as_const = it->cast (as_ref ());
350+ self = as_const.template try_cast <Type>();
356351 }
357352
358- return nullptr ;
353+ return self ;
359354 }
360355
361356 /* ! @copydoc try_cast */
362357 template <typename Type>
363358 [[nodiscard]] Type *try_cast () {
364- if (const auto &info = type_id<Type>(); node && *node->info == info) {
365- return any_cast<Type>(&storage);
366- } else if (node) {
367- for (auto *it = node->base ; it; it = it->next ) {
368- if (Type *base = it->cast (as_ref ()).template try_cast <Type>(); base) {
369- return base;
370- }
371- }
359+ auto *self = any_cast<Type>(&storage);
360+
361+ for (auto *it = node ? node->base : nullptr ; it && !self; it = it->next ) {
362+ self = it->cast (as_ref ()).template try_cast <Type>();
372363 }
373364
374- return nullptr ;
365+ return self ;
375366 }
376367
377368 /* *
@@ -416,7 +407,7 @@ class meta_any {
416407 */
417408 [[nodiscard]] bool allow_cast (const meta_type &type) {
418409 if (auto other = std::as_const (*this ).allow_cast (type); other) {
419- if (other.storage . owner ()) {
410+ if (other.owner ()) {
420411 std::swap (*this , other);
421412 }
422413
@@ -435,12 +426,7 @@ class meta_any {
435426 template <typename Type>
436427 [[nodiscard]] meta_any allow_cast () const {
437428 const auto other = allow_cast (internal::meta_node<std::remove_cv_t <std::remove_reference_t <Type>>>::resolve ());
438-
439- if constexpr (std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t <Type>>) {
440- return other.storage .owner () ? other : meta_any{};
441- } else {
442- return other;
443- }
429+ return (!std::is_reference_v<Type> || std::is_const_v<std::remove_reference_t <Type>> || other.owner ()) ? other : meta_any{};
444430 }
445431
446432 /* *
@@ -451,7 +437,7 @@ class meta_any {
451437 template <typename Type>
452438 bool allow_cast () {
453439 if (auto other = std::as_const (*this ).allow_cast (internal::meta_node<std::remove_cv_t <std::remove_reference_t <Type>>>::resolve ()); other) {
454- if (other.storage . owner ()) {
440+ if (other.owner ()) {
455441 std::swap (*this , other);
456442 return true ;
457443 }
@@ -1397,7 +1383,7 @@ bool meta_any::set(const id_type id, Type &&value) {
13971383 }
13981384
13991385 for (auto *it = node->base ; it; it = it->next ) {
1400- const auto as_const = it->cast (as_ref ());
1386+ const auto & as_const = it->cast (as_ref ());
14011387
14021388 if (auto other = as_const.allow_cast (type); other) {
14031389 return other;
0 commit comments