Provide checkedAdd and checkedMul functions, providing checked arithmetic on signed 64 bit integers.
It would be great to have checked* utilities which work with all the different kinds of integers.
|852 ↗||(On Diff #135743)|
Once this lands, I think people will want to use it for more than just int64_t. To make this generic we'll need templates, and that introduces a cyclic-dependency problem with APInt.h.
Sorry for not thinking of this earlier, but: wdyt of moving this to Support/CheckedArithmetic.h (or similar)?
|21 ↗||(On Diff #135743)|
Could you move the APInt include up to the right spot?
|26 ↗||(On Diff #135743)|
Please clang-format your diffs.
|29 ↗||(On Diff #135743)|
llvm::function_ref is more appropriate for non-owning callables.
|33 ↗||(On Diff #135765)|
I'm suggesting adding 'typename F' to the template parameter list and using F as the type of Op. It's shorter, and since there's no std::function, it signals to the reader that there are no unnecessary copies happening. Taken together this makes the code easier to read.