[edit] Beaten by Dave_Sinkula. [/edit]
[edit=2] Is is portable to rely on true being 1, rather than some other value like -1?
Code:
result += *dst > std::numeric_limits<T>::max() - src;
[/edit]
The best way I can think of to detect overflow would be to use something like this.
Code:
if(b > MAX - a) {
// overflow
}
That's assuming that you know the maximum possible value for the given type, of course. Something you can easily determine with
Code:
std::numeric_limits<type>::max()
BTW, why did you have parentheses around your call?
Code:
(std::numeric_limits<Unsigned>::max)()