Thread overview
Using a range as a reference
Aug 24, 2013
Paolo Invernizzi
Aug 24, 2013
David
Aug 24, 2013
Paolo Invernizzi
Aug 24, 2013
H. S. Teoh
Aug 24, 2013
Paolo Invernizzi
August 24, 2013
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
do you mean refRange? http://dlang.org/phobos/std_range.html#.refRange
August 24, 2013
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
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
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