mirror of
https://github.com/boostorg/conversion.git
synced 2026-05-05 12:14:10 +02:00
Allow using polymorphic_downcast and polymorphic_cast in constexpr (#30)
This commit is contained in:
@@ -38,6 +38,48 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
constexpr bool compile_time_polymorphic_cast_check() {
|
||||
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||
Derived derived;
|
||||
Base* base = &derived;
|
||||
return polymorphic_cast<Derived*>(base) != nullptr;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(
|
||||
compile_time_polymorphic_cast_check(),
|
||||
"polymorphic_cast does not work at compile time"
|
||||
);
|
||||
|
||||
constexpr bool compile_time_polymorphic_downcast_check() {
|
||||
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||
Derived derived;
|
||||
Base* base = &derived;
|
||||
return polymorphic_downcast<Derived*>(base) != nullptr;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(
|
||||
compile_time_polymorphic_downcast_check(),
|
||||
"polymorphic_downcast does not work at compile time"
|
||||
);
|
||||
|
||||
constexpr bool compile_time_polymorphic_downcast2_check() {
|
||||
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||
Derived derived;
|
||||
Base& base = derived;
|
||||
Derived& derived_again = polymorphic_downcast<Derived&>(base);
|
||||
(void)derived_again;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(
|
||||
compile_time_polymorphic_downcast2_check(),
|
||||
"polymorphic_downcast does not work at compile time"
|
||||
);
|
||||
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user