Re: BigInt foreach loop

2017-08-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/9/17 9:08 PM, Steven Schveighoffer wrote: Right, but this is not a limitation of the API, just the implementation. It could be improved. https://issues.dlang.org/show_bug.cgi?id=17736 Based on H.S. Teoh's comment in the bug report, this actually is invalid. That's a tough requirement.

Re: BigInt foreach loop

2017-08-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/9/17 5:40 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 09, 2017 at 09:34:26PM +, Q. Schroll via Digitalmars-d-learn wrote: On Friday, 4 August 2017 at 16:40:08 UTC, Stefan Koch wrote: [..] foreach(x;A .. B) it's lowerd to auto limit = B; auto key = A; for(auto x = key;ke

Re: BigInt foreach loop

2017-08-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 09, 2017 at 09:34:26PM +, Q. Schroll via Digitalmars-d-learn wrote: > On Friday, 4 August 2017 at 16:40:08 UTC, Stefan Koch wrote: > > [..] > > > > foreach(x;A .. B) > > it's lowerd to > > auto limit = B; > > auto key = A; > > for(auto x = key;key < limit;++key) > > { > > // use

Re: BigInt foreach loop

2017-08-09 Thread Q. Schroll via Digitalmars-d-learn
On Friday, 4 August 2017 at 16:40:08 UTC, Stefan Koch wrote: [..] foreach(x;A .. B) it's lowerd to auto limit = B; auto key = A; for(auto x = key;key < limit;++key) { // use x } That's enough to know that the foreach loop does not reuse the space for the iteration variable. That was what I c

Re: BigInt foreach loop

2017-08-04 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 4 August 2017 at 13:09:55 UTC, Steven Schveighoffer wrote: Any foreach range statement like this: foreach(var; A .. B) is treated as if you wrote: for(auto var = A; var < B; ++var) So it's pretty much exactly like what you wrote, just the initializer is different but the result

Re: BigInt foreach loop

2017-08-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/4/17 8:49 AM, Q. Schroll wrote: One can do BigInt n = returnsBigInt(); foreach (i; BigInt(0) .. n) { .. } How is this implemented? The code for BigInt is very large and I didn't find it. And is it more efficient than for (BigInt i = 0; i < n; ++i) { .. } Any foreach range

Re: BigInt foreach loop

2017-08-04 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 4 August 2017 at 12:49:30 UTC, Q. Schroll wrote: One can do BigInt n = returnsBigInt(); foreach (i; BigInt(0) .. n) { .. } How is this implemented? The code for BigInt is very large and I didn't find it. And is it more efficient than for (BigInt i = 0; i < n; ++i) { .. } as

BigInt foreach loop

2017-08-04 Thread Q. Schroll via Digitalmars-d-learn
One can do BigInt n = returnsBigInt(); foreach (i; BigInt(0) .. n) { .. } How is this implemented? The code for BigInt is very large and I didn't find it. And is it more efficient than for (BigInt i = 0; i < n; ++i) { .. } as incrementing is a costly operation?