I am implementing an iterator for a range of adapters that lazily evaluates something in the original range. This means: dereferencing an iterator should dereference the base iterator and apply some operation to the result, and then return the result of this operation.
T operator*() const {
return someOperation(*original_iterator);
}
How can I implement operator->similar to this operator*? If you look at other iterator implementations, they usually return T*. But I cannot return the pointer, since the "pointer to the object" is temporary, calculated on the fly.
What is the usual guide in this case? Can I just get it back T?
Although I personally do not need this operator (I could also use (*i).minstead i->m, and the standard algorithms do not seem to depend on either ->), I would like my iterator to strictly correspond to the concept ForwardIterator, which is a specialization InputIteratorthat requires the implementation of this operator.
source
share