Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 24, 2013 Using a range as a reference | ||||
---|---|---|---|---|
| ||||
Hi all, I've a custom generator, and is modelled as a structure forwardRange, and I want to be able to use it like this, printing the first ten fibonacci: --- struct ForEacher(Range){ Range* r; this(ref Range r_){ r=&r_; } @property bool empty(){ return r.empty; } @property auto front(){ return r.front; } void popFront(){ r.popFront(); } } auto forEacher(Range)(ref Range r){ return ForEacher!Range(r); } void main(){ auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1); foreach(e; fib.forEacher){ static i = 0; i++; if(i == 5) break; writeln(e); } foreach(e; fib.forEacher){ static j = 0; j++; if(j == 5) break; writeln(e); } or writeln(fib.forEacher.take(5)); writeln(fib.forEacher.take(5)); } --- There's something in phobos like the 'forEacher'? What is the best strategy for something like that? |
August 24, 2013 Re: Using a range as a reference | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paolo Invernizzi | do you mean refRange? http://dlang.org/phobos/std_range.html#.refRange |
August 24, 2013 Re: Using a range as a reference | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | On Saturday, 24 August 2013 at 19:51:14 UTC, David wrote:
> do you mean refRange?
> http://dlang.org/phobos/std_range.html#.refRange
Exactly, thank you!
I've missed it as it is not listed in the tables of the range documentation, like the others, but only in the top-index...
- Paolo Invernizzi
|
August 24, 2013 Re: Using a range as a reference | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paolo Invernizzi | On Sat, Aug 24, 2013 at 10:02:56PM +0200, Paolo Invernizzi wrote: > On Saturday, 24 August 2013 at 19:51:14 UTC, David wrote: > >do you mean refRange? http://dlang.org/phobos/std_range.html#.refRange > > Exactly, thank you! > I've missed it as it is not listed in the tables of the range > documentation, like the others, but only in the top-index... [...] That would be a documentation bug. Please file a bug on http://d.puremagic.com/issues. T -- Arise, you prisoners of Windows / Arise, you slaves of Redmond, Wash, / The day and hour soon are coming / When all the IT folks say "Gosh!" / It isn't from a clever lawsuit / That Windowsland will finally fall, / But thousands writing open source code / Like mice who nibble through a wall. -- The Linux-nationale by Greg Baker |
August 24, 2013 Re: Using a range as a reference | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Saturday, 24 August 2013 at 20:24:47 UTC, H. S. Teoh wrote: > On Sat, Aug 24, 2013 at 10:02:56PM +0200, Paolo Invernizzi wrote: >> >> I've missed it as it is not listed in the tables of the range >> documentation, like the others, but only in the top-index... > > That would be a documentation bug. Please file a bug on > http://d.puremagic.com/issues. > Done: http://d.puremagic.com/issues/show_bug.cgi?id=10885 - Paolo Invernizzi |
Copyright © 1999-2021 by the D Language Foundation