#pragma once #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int BAD_CAST; } } /** Checks type by comparing typeid. * The exact match of the type is checked. That is, cast in the ancestor will be unsuccessful. * In the rest, behaves like a dynamic_cast. */ template typename std::enable_if::value, To>::type typeid_cast(From & from) { if (typeid(from) == typeid(To)) return static_cast(from); else throw DB::Exception("Bad cast from type " + demangle(typeid(from).name()) + " to " + demangle(typeid(To).name()), DB::ErrorCodes::BAD_CAST); } template To typeid_cast(From * from) { if (typeid(*from) == typeid(typename std::remove_pointer::type)) return static_cast(from); else return nullptr; }