Mixed int/BigInt foreach interval

Jonathan M Davis jmdavisProg at gmx.com
Tue Sep 27 13:02:37 PDT 2011


On Tuesday, September 27, 2011 12:22 bearophile wrote:
> Jonathan M Davis:
> > > foreach (i; 1 .. BigInt(10)) {}
> > 
> > No. That's foreach. BigInt isn't going to work with the .. syntax
> > regardless of what isIntegral does. I assume what you're really asking
> > is whether
> 
> I'm asking about foreach, not about iota. Fixing iota is easy, it's just a
> matter of changing Phobos.
> 
> This is why at the top of my original post I have written:
> > In my opinion it's important to make BigInts work in most places where
> > normal ints work. I think it's even worth modifying D language a bit (if
> > and where necessary) to allow this.
> 
> The point of my post was to talk about foreach. The title of this thread is
> "Mixed int/BigInt foreach interval".

I'd be _very_ surprised to see that happen, since BigInt is in Phobos as 
opposed to being at the language level. Ranges could be added to foreach, 
because they're entirely API-based, and so the compiler doesn't have to care 
about what Phobos is doing. It just has to do the appropriate lowerings. But 
BigInt is a specific type in Phobos. Making it work with foreach would mean 
that the compiler would have to know and understand about BigInt. I don't 
expect that to ever happen. Best case, I would think that you could get it to 
work by having BigInt be implicitly convertible to int, but since that's a 
narrowing conversion, that's a _bad_ idea IMHO.

- Jonathan M Davis


More information about the Digitalmars-d mailing list