Re: Iterator implementation questions: copy constructor and postfix increment
Scott Gifford wrote:
"Victor Bazarov" <v.Abazarov@comAcast.net> writes:
Scott Gifford wrote:
I'm having a similar problem implementing postfix increment
(operator++(int)). I basically need to return a copy of the
iterator at the previous position in the database, but again I
can't copy the database cursor or construct a new cursor because of
Don't implement post-increment. At all. Use pre-increment.
That's what I've done so far, but I was concerned that it might not
work with all of the standard algorithms without a post-increment
operator, mostly because the docs at SGI say that an input iterator
must implement post-increment:
Is it safe to assume that the standard algorithms that work with an
input iterator all use pre-increment so I don't have to worry about
No, it's not safe at all. If you want to conform (and use standard
algorithms), then you're stuck with post-increment.
Sorry, I didn't realise you needed to strictly conform to the input
iterator requirements set by the Standard. You said "similar"...
The idea is that your operation
should give you the entry to the database. You shouldn't concern
yourself with copying iterators, only with comparing them and with
dereferencing them. What if every increment causes a fetch from
the database and stores the fetched value (I am not versed in the
database terminology to explain correctly what I mean). Could there
be a "pointer" or a "reference" to the stored record? Could you
make a copy of the record?
Essentially your task in to provide the functioning operator*. You
need to make sure that *it and *it++ do the same thing (return the
same value for the same 'it').
There are probably folks here who deal with databases and who better
understand your "cannot copy the cursor" statement (and AFAIUI, your
idea of sharing the cursor between all iterators may be the right
path to take, what if instead of tranfer of ownership you just count
the references?). If not, maybe asking in the newsgroup for DB
development could prove fruitful?
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask