25 #include <type_traits>
27 namespace catapult {
namespace utils {
36 template<
typename TEnum>
38 return static_cast<std::underlying_type_t<TEnum>
>(value);
44 template<
typename TSource,
typename TDest>
46 using dest_limits = std::numeric_limits<TDest>;
47 using source_limits = std::numeric_limits<TSource>;
49 source_limits::min() < dest_limits::min() || source_limits::max() > dest_limits::max(),
50 "checked_cast can only be used when data truncation is possible");
52 if (value < dest_limits::min() || value > dest_limits::max())
55 return static_cast<TDest>(value);