#pragma once #include #include /** Проверяет совпадение типа путём сравнения typeid-ов. * Проверяется точное совпадение типа. То есть, cast в предка будет неуспешным. * В остальном, ведёт себя как 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 std::bad_cast(); } template To typeid_cast(From * from) { if (typeid(*from) == typeid(typename std::remove_pointer::type)) return static_cast(from); else return nullptr; }