Suppose I have something like this:
class Collection { private: typedef std::vector< std::shared_ptr<Something> >::iterator Iterator; std::vector< std::shared_ptr<Something> > data_; public: Iterator begin() {return data_.begin()} Iterator end() {return data_.end()} }
When I use an instance of Collection::Iterator , I need to dereference it once to get the std::shared_ptr<Something> object and get the Something object again.
But if I want to make std::shared_ptr<Something> only an implementation detail, it is reasonable that after one dereferencing I should get a Something object.
I.e:
Collection collection; Collection::Iterator it = collection.begin(); Something firstMember = *it;
My question is: do I need to make Iterator as a nested Collection class from scratch and implement all the functions necessary for a random access iterator here http://www.cplusplus.com/reference/std/iterator/ or is there some known approach? Maybe C ++ 11?
source share