Template version of std::abs

Solution 1:

See LWG issue 2192. Currently, std::abs(x-y) < 2 fails if x and y are unsigned. This catches a subtle programming error. With the proposed change, it compiles but does entirely the wrong thing. abs(3u-4u) would be much larger than 2, in fact it's UINT_MAX.

Solution 2:

This suffers the usual problem of matching everything.

An example of a type for which abs makes sense but this implementation does not is complex<double>.