The evil return of "convertable to bool"

chris caj@cs.york.ac.uk
Tue Oct 26 12:28:00 GMT 2004


Sorry for bringing this up again, but I just wanted it to be on the list 
in case someone wants to query it later...

In the currently online <tuple> specification, the operator< is defined 
as returning:
(bool)(get<0>(t) < get<0>(u)) || !((bool)(get<0>(u) < get<0>(t)) && 
(ttail < utail)

I asked where the various (bool)s were there, and was told (as has been 
discussed previously) that they are there as the return values of these 
functions only have to be convertable to bool and may overload || and 
&&. I did not however put in the casts, as if it was decided that 
libstdc++ had to cast everything to bool which we were going to then 
apply && or || to, then this would involve (I believe) a fairly complete 
look through the library (for example, these bool casts aren't on 
operator< on std::pairand much of the contents of <algorithm>).

Chris



More information about the Libstdc++ mailing list