max() in phobos, and English logic operators
Daniel Keep
daniel.keep.lists at gmail.com
Thu Nov 9 18:38:52 PST 2006
David Qualls wrote:
> == Quote from Bill Baxter (dnewsgroup at billbaxter.com)'s article
>
>> But my point was just that the extra information is not
> necessary for
>> the macro version. The intended meaning of max(x,0) is clear
> enough to
>> the reader, so the compiler should be able to handle it without
>> complaining, too.
>> --bb
>
> EXACTLY! I also think you (mostly) nailed it with
>
>> About signed types, I think
>> auto c = max(a,b)
>> should pick the same type for c that the compiler would pick for
>> auto c = a+b;
>
> except I don't think max(10U , -1) should return -1 cast to an
> unsigned!
One thing I did when I was playing around with some MMX code was write a
template that figured out the "expression-safe" type of something.
Basically, it was the type for which any expression involving the base
type could be contained in. I used it to ensure that stuff like int+int
wouldn't overflow.
You could always say that when combining a signed and unsigned type,
take the signed type large enough to hold either. If the user has a
problem with having to cast it back, tell him to use arguments of the
same type, damnit!
"But I don't *wanna*!"
"Tough. Don't wanna deal with types? Go program in PHP."
"I'll behave..."
-- Daniel
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d-learn
mailing list