template<typename R, typename E>
R safe_cast(const E &e)
static_assert(sizeof(R) >= sizeof(E), "unsafe cast attempt");
static_assert evaluates an expression at compile time and throw an error in case it fails. The first parameter is a boolean condition and the second one is the string that appears in the IDE in case the condition is not valid.