Don wrote:
Andrei Alexandrescu wrote:
max takes heterogeneous parameters to catch situations like max(a, 0).

Andrei

Yeah. It's a shame we can't use the ?: type rule for common parameters, since max(T, U) only makes sense when T and U have a common type. So we get code bloat, with unnecessary template instantiations. But it'd be too complicated otherwise, I think. C'est la vie.

La vie n'est pas si mal. Looking through the implementation of max you'll see that it carefully selects the compatible types, and also computes the correct type for the return value.

I don't think there's much, if any, code bloat as well. The operations generated are specialized for the respective types as if you wrote things by hand.


Andrei

Reply via email to