To create a valid iterator, you must make sure that std :: iterator_traits is valid. This means that you must set the iterator category among other things.
The iterator should implement iterator (), iterator (iterator & &), iterator (iterator const &), operator ==, operator! =, operator ++, operator ++ (int), operator *, operator = and operator->. Itβs also nice to add the <operator and the + operator if you can (you cannot always, for example, linked lists.)
template <typename T> class foo { public: using value_type = T; class iterator { public: using value_type = foo::value_type; using iterator_category = std::random_access_iterator_tag;
See: http://en.cppreference.com/w/cpp/iterator/iterator_traits for more information on what you need to create a valid iterator. (Note: you also need certain properties as a valid "container", for example .size ())
Ideally, you should use member functions to start and end, but this is not required ... you can also overload std :: begin and std :: end. If you do not know how to do this, I suggest you use member functions.
You must create begin () const and end () const, but it must be an alias for cbegin (), NEVER the same as begin ()!
Exaeta
source share