[Xapian-devel] Iterators

Olly Betts olly at survex.com
Thu May 17 00:33:54 BST 2012


On Wed, May 16, 2012 at 06:57:34PM +0400, Michael Uvarov wrote:
> Is there way to clone iterators?
> 
> Something like this:
> 
>         Xapian::TermIterator x(y); // or x = y
>         // Can we change x independently of y?
>         x++;
>         // No, we can not. y was also modified.
>         assert(*x != *y);

The input iterators like TermIterator have the standard C++
input iterator semantics, so advancing x invalidates y.  There's not
a direct way to clone an iterator - you'd have to get a fresh one from
the parent object and call skip_to() on it to advance it to the same
position.

The bidirectional iterators (like MSetIterator and ESetIterator) can 
be cloned just by making a copy.

Cheers,
    Olly



More information about the Xapian-devel mailing list