| 227 | /// Signed addition with well-defined behaviour on overflow (as unsigned) |
| 228 | template <typename SignedInt> |
| 229 | SignedInt SafeSignedAdd(SignedInt u, SignedInt v) { |
| 230 | using UnsignedInt = typename std::make_unsigned<SignedInt>::type; |
| 231 | return static_cast<SignedInt>(static_cast<UnsignedInt>(u) + |
| 232 | static_cast<UnsignedInt>(v)); |
| 233 | } |
| 234 | |
| 235 | /// Signed subtraction with well-defined behaviour on overflow (as unsigned) |
| 236 | template <typename SignedInt> |