food for thought - swift 5 released - bottom types, string interpolation, and stuff.
Walter Bright
newshound2 at digitalmars.com
Sun Apr 14 08:37:26 UTC 2019
On 4/13/2019 5:27 PM, Timon Gehr wrote:
> My point exactly. x & 1 is not the best implementation of isOdd for all
> integer-representing types of x,
It is for all the basic integral types in D, and I would expect anyone
implementing their own integral type to make x&1 work.
I.e. when you make your own integral type, the onus is on you to make the
integer operators do the expected thing with it. D's template constraints should
be good enough to recognize x&1 and make it efficient for the user defined type
implementation.
isOdd() would be problematic for floating point types, which is a reason to
avoid doing it for them, so people don't get surprised. (What is isOdd(infinity)
supposed to do? true? false? throw exception? abort? launch nuclear missiles?)
More information about the Digitalmars-d
mailing list