I have several templates that can have either a map or a vector as the main container. I would like the template to expose constant iterators for elements. Most of the information I read about how to set iterators (e.g. this accu article ) uses the form
typedef std::vector<int>::iterator iterator;
typedef std::vector<int>::const_iterator const_iterator;
iterator begin() { return values.begin(); }
iterator end() { return values.end(); }
This really doesn’t work for a template that uses a map, though, since the template can no longer use it it->SomeMemberFunc(), but rather should use it to access the elements it->second.SomeMemberFunc(). Therefore, I am looking to show the iterator on map elements that do not give access to keys, but only to map values.
How to do it?
source
share