23 #include <type_traits>
42 template<
typename Base,
typename Derived>
43 struct is_base_of : std::is_base_of<Base, Derived>
45 template<
typename Base,
typename Derived>
46 struct is_base_of<Base*, Derived*> : is_base_of<Base, Derived>
49 template<
typename Base,
typename Derived>
50 struct is_base_of<
std::shared_ptr<Base>, std::shared_ptr<Derived>>
51 : is_base_of<Base, Derived>
57 struct is_pointer : std::is_pointer<T>
60 struct is_pointer<
std::shared_ptr<T>> : std::true_type
63 template<
typename T,
typename U,
bool check>
68 template<
typename T,
typename U>
69 struct _downcast<T,
U, false>
71 static_assert(is_base_of<U, T>::value,
"invalid downcast");
80 noexcept(is_pointer<T>::value)
84 return static_cast<T
>(u);
86 return dynamic_cast<T
>(u);
97 template<
typename T,
typename U>
98 struct _downcast<
std::shared_ptr<T>,
U, false>
100 static_assert(is_base_of<U, std::shared_ptr<T>>::value,
"invalid downcast");
108 return std::static_pointer_cast<T>(u);
110 return std::dynamic_pointer_cast<T>(u);
117 template<
typename T,
typename U>
118 struct _downcast<T,
U, true>
125 T t = _downcast<T, U, false>::cast(u);
133 template<
typename T,
typename U>
140 noexcept(is_pointer<T>::value)
143 return _downcast<T, U, is_pointer<T>::value>::cast(u);
Definition: formula.hh:1671