Is this range behaviour correct?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 14 05:29:26 PDT 2013


On 3/14/13 6:45 AM, Andrea Fontana wrote:
> On Thursday, 14 March 2013 at 10:08:53 UTC, Andrea Fontana wrote:
>> I'm trying to implement a db cursor as simple InputRange. I can't
>> implement as forward range because using c-api I can't clone/save cursor.
>>
>> I wrote popFront() front() and empty() method and my range works fine.
>>
>> Using on a foreach() it browses all elements inside range until range
>> is exausthed.
>>
>> If i do another foreach() it doesn't restart (empty() is called and it
>> returns true, of course).
>>
>> Is it the correct behaviour of a inputrange or have i missed something?
>
> Maybe I got it. I implemented this range as class, so it is passed as
> reference to foreach, usually ranges are struct and passed by value. I
> guess this is the problem.
>
> Is there a way to make a class based range like a struct one?

Add .save() to it.

Andrei


More information about the Digitalmars-d-learn mailing list