#pragma once #include namespace DB { namespace ErrorCodes { extern const int LOGICAL_ERROR; } template To safe_cast(From from) { constexpr auto max = std::numeric_limits::max(); if (from > max) throw Exception(ErrorCodes::LOGICAL_ERROR, "Overflow ({} > {})", from, max); return static_cast(from); } }