digitalmars.D.learn - Using a range as a reference
- Paolo Invernizzi (32/32) Aug 24 2013 Hi all,
- David (2/2) Aug 24 2013 do you mean refRange?
- Paolo Invernizzi (5/7) Aug 24 2013 Exactly, thank you!
- H. S. Teoh (7/14) Aug 24 2013 [...]
- Paolo Invernizzi (3/10) Aug 24 2013 Done: http://d.puremagic.com/issues/show_bug.cgi?id=10885
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?
Aug 24 2013
On Saturday, 24 August 2013 at 19:51:14 UTC, David wrote:do you mean 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
Aug 24 2013
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:[...] 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 Bakerdo you mean 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...
Aug 24 2013
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:Done: http://d.puremagic.com/issues/show_bug.cgi?id=10885 - Paolo InvernizziI'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.
Aug 24 2013