TIterator Clone?


Would it be possible to add a Clone method to the TIterator interface ?

I miss that method for some of my custom iterators that do internally use other TIterators (to implement their copy and assignment operators).

Not mission critical, but would be nice, or is there a reason why it’s not there ?


All iterators have copy and assignment operators, so you should call those in the copy ctor of your own iterator.

Cheers, Fons.


Maybe I did not expressed myself correctly.

I have a custom iterator for a class A :

class AIterator : public TIterator
AIterator(const A& a, some_range);

TIterator* fHelperIterator;

where fHelperIterator I get from A::CreateIterator() for instance. This one iterates over all values in a. Now I want AIterator to loop only over a given range. So AIterator reuses the iterator on a, and filters the results. That way AIterator can “reuse” a’s iterator, whatever that one is.

Problem in this case is that when copying one AIterator into another one, I do not want to share the fHelperIterator pointers, but get two separate ones, and this I don’t know how to do without a Clone :

AIterator::AIterator(const AIterator& rhs)
: fHelperIterator(rhs.fHelperIterator.Clone())

Not so sure this explanation is clearer, but well, it’s there :wink:


Yoy could do something like this in you copy ctor:

fHelperIterator = CreateIterator();
fHelperIterator = rhs.fHelperIterator;

– Fons