max() in phobos, and English logic operators
Bill Baxter
dnewsgroup at billbaxter.com
Wed Nov 8 16:38:24 PST 2006
Sean Kelly wrote:
> Bill Baxter wrote:
>>
>> Especially annoying for containers parameterized by numeric type. Then
>> you don't know what to use for the literal you're comparing against,
>> so you've got to use a cast.
>>
>> T x = 17; // could be float,double,real,int etc
>> std::max(x, cast(T)0); // ugh.
>
> In all fairness, this can be rewritten as:
>
> std::max<T>( x, 0 );
The cast is not so bad in real C++ either:
std::max(x, T(0));
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
More information about the Digitalmars-d-learn
mailing list