On Thursday, 14 March 2013 at 13:20:51 UTC, Andrea Fontana wrote:
On Thursday, 14 March 2013 at 12:29:26 UTC, Andrei Alexandrescu
wrote:
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.
Add .save() to it.
Andrei
I can't add save and create a forward range: c-api doesn't
allow me to clone db cursor.
But think about it. You say you can't save, but you want pass by
value to preserve state. If you can preserve state, doesn't that
mean you just saved?
Once you've passed your "can't preserve state" to a foreach, then
your range is consumed. So yes, it is correct behavior.
Most input ranges should model reference semantics when
passed/copied by value. If somebody modifies the range, all
ranges are affected. The tough part is usually preserving correct
state.