Skip to content

Commit b2ef5b3

Browse files
committed
Fix is() to handle polimorphic sidecast
1 parent b1754db commit b2ef5b3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

include/cpp2util.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,19 @@ auto is( X const& ) -> bool {
531531
}
532532

533533
template< typename C, typename X >
534-
requires (std::is_base_of_v<X, C> && !std::is_same_v<C,X>)
534+
requires (
535+
( std::is_base_of_v<X, C> ||
536+
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
537+
) && !std::is_same_v<C,X>)
535538
auto is( X const& x ) -> bool {
536539
return dynamic_cast<C const*>(&x) != nullptr;
537540
}
538541

539542
template< typename C, typename X >
540-
requires (std::is_base_of_v<X, C> && !std::is_same_v<C,X>)
543+
requires (
544+
( std::is_base_of_v<X, C> ||
545+
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
546+
) && !std::is_same_v<C,X>)
541547
auto is( X const* x ) -> bool {
542548
return dynamic_cast<C const*>(x) != nullptr;
543549
}

0 commit comments

Comments
 (0)