| ▲ | tialaramex 4 hours ago | |
> __builtin_add_overflow Exists and it’s basically free on most CPUs out there. This is a very C-flavoured "solution". For those who haven't seen it this involves a pointer (!) and we're going to compute the addition, write the result to the pointed-at integer and then if that didn't fit and so it overflowed we'll return true otherwise false. The closest Rust analogy would be T::carrying_add which returns a pair to achieve a similar result. And yeah, checking is "basically free" unless it isn't, that's not different. If you haven't measured you don't know, same in every programming language. It's never been true that you can't write correct software in C or C++ the problem is that in practice you won't do so. | ||