Add safe cast function
Description
Based on !949 (comment 556811466), it is useful to have a function that makes casting between different integer types safer.
Expected behavior
safe_cast
shall throw an exception if the value is changed during conversion. A possible signature
template<class T, class S,
std::enable_if_t<details::both_integral<T, S>::value> * = nullptr>
constexpr T safe_cast(S s) noexcept(false)
Similar function can be done for floating conversion with an epsilon for comparison
Definition of Done
-
Add safe cast
Look for places where this should be used; e.g.
-
retrieving parameters of ROS2 nodes -
where static_cast
is used