I’m writing my own implementation of the C++ STL map container. Now I’m trying to implement the iterator. It should allow you to do something like iter->first and iter->second that returns the key/value respectively and where iter is an object not a pointer. I’m wondering how I should overload this? It’s a bit confusing because I’m not sure what the return type should be; it has to be an object with members first/second I suppose. Is it typical to return a reference to a wrapper/interface object or something like that?
Share
The value_type of a standard map is
std::pair<const KeyType, MappedType>.To achieve normal pointer semantics,
operator*returns a reference, whereasoperator->returns a pointer.