Mixed int/BigInt foreach interval
Peter Alexander
peter.alexander.au at gmail.com
Tue Sep 27 16:16:29 PDT 2011
On 27/09/11 3:06 AM, Andrei Alexandrescu wrote:
> On 9/26/11 6:49 PM, bearophile wrote:
>> Jonathan M Davis:
>>
>>> Why is it bad? isIntegral was specifically designed for testing that
>>> a type was
>>> one of byte, ubyte, short, ushort, int, uint, long, and ulong, and
>>> that's
>>> exactly what it's doing.
>>
>> Going back to my original post, is changing the semantics of
>> isIntegral enough to allow code like this to compile and run?
>>
>> foreach (i; 1 .. BigInt(10)) {}
>>
>> Bye,
>> bearophile
>
> Well isIntegral was designed indeed for primitive integral types. The
> problem with having isIntegral!BigInt dilutes the meaning of isIntegral
> because there are significant differences between
>
> Without having thought a lot of this, my impression is we need a sort of
> isMonoid!(T, "+", 0) as a guard for iota.
>
>
> Andrei
I think this is the best route, although it is unfortunate that
is*Integral* fails on Big*Integer*. If an integer isn't integral then I
don't know what is :-)
isIntegral should have been called isIntegralPrimitive or
isMachineInteger or something along those lines if that was what it was
designed for. I guess it's too late for that now.
Or could it be deprecated then re-purposed at the end of the deprecation
period?
More information about the Digitalmars-d
mailing list