
Thorsten Wrote :
1. AFIICT it is not possible to let operator->() return a tuple of references s.t. ->second would yeild T& instead of T*. Reason: the pointer might be null.
Well, you could throw a bad_pointer here, but....
2. Operator*() now returns a tuple [key,T*]; this is necessary because you may need access to both the key inside e.g predicates for algorithms. Operator->() also returns the same tuple, so that you can make the familiar loop in #1. The question is #1 is necessary/wanted given that it removes the current behavior where operator->() returns a T* s.t. you can more easily access the mapped object. Would it be preferable to keep operator-<() with a T* return type?
I think the important thing here is to provide a consistent behaviour. ptr_map is an extension to std::map, and so should behave like std::map. As Felipe says, any deviations from the interface of std::map will make it harder to write generic code, and should be avoided where possible. I think it would be surprising to users if the following two operations returned different types : (*i).second i->second On a std::map they are the same, so I think they should be the same for ptr_map. Sam