Input Iterator for a shared_ptr

Posted by Baz on Stack Overflow See other posts from Stack Overflow or by Baz
Published on 2012-10-11T09:24:19Z Indexed on 2012/10/11 9:37 UTC
Read the original article Hit count: 118

Filed under:

I have an iterator which contains the following functions:

    ...
    T &operator*() { return *_i; }
    std::shared_ptr<T> operator->() { return _i; }

private:
    std::shared_ptr<T> _i;
    ...

How do I get a shared pointer to the internally stored _i?

std::shared_ptr<Type> item = ???

Should I do:

MyInterfaceIterator<Type> i;
std::shared_ptr<Type> item = i.operator->();

Or should I rewrite operator*()?

© Stack Overflow or respective owner

Related posts about c++