std::max: if versus ?:

Paolo Carlini paolo.carlini@oracle.com
Thu Sep 20 12:07:00 GMT 2012


On 09/20/2012 01:55 PM, Marc Glisse wrote:
> Hello,
>
> I noticed that std::max is implemented as:
>
>       //return  __a < __b ? __b : __a;
>       if (__a < __b)
>         return __b;
>       return __a;
>
> Notice how it doesn't use the ?: code but the "if" version instead. 
> Looking at the history, this seems to come from SGI. Does someone know 
> why it was done this way?
I'm going to tell you something very vague and non technical, but in the 
past, outside std::max, I had quite often to use the above instead of a 
conditional operator as a second thought, when (maybe on a less common 
target) a test "unexpectedly" failed with a conversion error. Does that 
help you figuring out the technical details of the issue?

Paolo.



More information about the Libstdc++ mailing list