template<class T> struct as_op {}; template<class T> constexpr as_op<T> as_obj{}; template<class T, class U> auto operator | (T* ptr, const as_op<U>& op) { return dynamic_cast<U*>(ptr); } #define as | as_obj struct Super{virtual ~Super()=default;}; struct A : Super{ }; int main() { Super* super = new A{}; auto a = super as<A>; delete super; }