C++ checked_cast implementation for a faster safe dynamic_cast