std::max: if versus ?:

Marc Glisse marc.glisse@inria.fr
Thu Sep 20 11:56:00 GMT 2012


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?

The reason I am asking is that if I add ?: support for vector types (à la 
OpenCL), with "if" std::max will still fail on vectors, but with ?: it 
would suddenly become accepted.

(concept checking would still fail though, but that could be fixed or 
ignored)
(there would still be a bit of work to adapt the fold-const.c code to 
recognize this vec_cond_expr as a max_expr, as happens for regular 
cond_expr)

-- 
Marc Glisse



More information about the Libstdc++ mailing list