[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] zOMG std::max({}, something)

From: Vadim Zeitlin
Subject: Re: [lmi] zOMG std::max({}, something)
Date: Sat, 19 Sep 2020 17:01:26 +0200

On Sat, 19 Sep 2020 10:31:14 +0000 Greg Chicares <gchicares@sbcglobal.net> 

GC> I didn't realize that "{}" acts like a zero of appropriate type here:
GC>  double d = -3.14;
GC>  int i = -17;
GC> -d = std::max(0.0, d);
GC> -i = std::max(0, i);
GC> +d = std::max({}, d);
GC> +i = std::max({}, i);
GC> ...and even here:
GC>  std::vector<some_type> v {0,1,2,3,4,5,6,7,8,9,10,11};
GC> -v.assign(12, 0);  // "0", or "0U", "0.0"...as the case may be
GC> +v.assign(12, {}); // a zero of deduced type

 Sure, it does... but it doesn't seem a good idea to use it like this from
readability point of view. I realize that it can be useful when switching
between double, int and currency, but hopefully it won't be necessary once
the code stabilizes on use whichever of them it will finally use.

 And even right now I think adding a tiny template helper at_least_zero(T)
could be a better idea than using max(T, {}).


Attachment: pgpFe9oxYR1kL.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]