1 #ifndef VCSN_MISC_CAST_HH
2 # define VCSN_MISC_CAST_HH
7 # define down_cast static_cast
8 # define down_pointer_cast std::static_pointer_cast
15 ::vcsn::detail::down_caster(__FILE__, __LINE__).cast
16 #define down_pointer_cast down_cast
32 template <
typename T,
typename U>
37 <<
file <<
':' <<
line <<
": " << msg
38 <<
" from " <<
typeid(U).name() <<
" to " <<
typeid(T).name()
43 template <
typename T,
typename U>
49 error<T, U>(
"down_casting nullptr");
50 T res =
dynamic_cast<const T
>(t);
52 error<T, U>(
"failed down_cast");
57 template <
typename T,
typename U>
63 error<std::shared_ptr<T>, std::shared_ptr<U>>(
"down_casting nullptr");
64 std::shared_ptr<T> res = std::dynamic_pointer_cast<T>(t);
66 error<std::shared_ptr<T>, std::shared_ptr<U>>(
"failed down_cast");
74 #endif // !VCSN_MISC_CAST_HH
down_caster(const char *f, int l)
A functor that captures the current location (to report errors), and provides "cast".
void error(const char *msg)
std::shared_ptr< T > cast(std::shared_ptr< U > t)
Special case for shared_ptr.