Skip to content

Commit 4fa9e48

Browse files
authored
Merge pull request #128 from filipsajdak/fsajdak-fix-is-for-sidecast
[FIX] is() function to handle polymorphic sidecast
2 parents 5a2b31c + afb76c9 commit 4fa9e48

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
@@ -574,13 +574,19 @@ auto is( X const& ) -> bool {
574574
}
575575

576576
template< typename C, typename X >
577-
requires (std::is_base_of_v<X, C> && !std::is_same_v<C,X>)
577+
requires (
578+
( std::is_base_of_v<X, C> ||
579+
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
580+
) && !std::is_same_v<C,X>)
578581
auto is( X const& x ) -> bool {
579582
return dynamic_cast<C const*>(&x) != nullptr;
580583
}
581584

582585
template< typename C, typename X >
583-
requires (std::is_base_of_v<X, C> && !std::is_same_v<C,X>)
586+
requires (
587+
( std::is_base_of_v<X, C> ||
588+
( std::is_polymorphic_v<C> && std::is_polymorphic_v<X>)
589+
) && !std::is_same_v<C,X>)
584590
auto is( X const* x ) -> bool {
585591
return dynamic_cast<C const*>(x) != nullptr;
586592
}

0 commit comments

Comments
 (0)