
Hello Thorsten, thanks for the ptr_vector clarifications. I have another question about ptr_map: I can declare a map iterator in the following way: ptr_map<string, SomeClass>::iterator i = m.begin(); Now, I'd expect to be able to compile the following, as with a normal map: string s = i->first; i->second.SomeMethod(); ...assuming SomeClass::SomeMethod() exists and is declared as public. However, "first" and "second" don't seem to exist in ptr_map. Could you shed some light on how I can iterate your map please? Best regards, Oleg.

Oleg Smolsky <oleg.smolsky <at> pacific-simulators.co.nz> writes:
However, "first" and "second" don't seem to exist in ptr_map. Could you shed some light on how I can iterate your map please?
Please see http://www.boost.org/libs/ptr_container/ doc/reference.html#map-iterator-operations HTH Thorsteb

Hello Thorsten, Thorsten Ottosen wrote on 29/10/2005 at 5:20 a.m.:
However, "first" and "second" don't seem to exist in ptr_map. Could you shed some light on how I can iterate your map please? Please see http://www.boost.org/libs/ptr_container/doc/reference.html#map-iterator-oper... Right, I see. Well, xxx.key() makes sense, but IMHO overloading operator*() to return the "value" is quite confusing. To me, it would make more sense to provide explicit accessors such as: iterator.key iterator.value
Or something similar. Whether these are function calls or not, IMHO, doesn't matter, but the readability would be a lot higher. Best regards, Oleg.

Right, I see. Well, xxx.key() makes sense, but IMHO overloading operator*() to return the "value" is quite confusing. To me, it would make more sense to provide explicit accessors such as: iterator.key iterator.value
Or something similar. Whether these are function calls or not, IMHO, doesn't matter, but the readability would be a lot higher.
I'll think about adding i.value() too. The reason that it is good to have operator*() return something is that we don't need another layer around algorithms to accomdate for the different syntax...so I can clone the values and put them in a ptr_vector quite easily: ptr_map<U,T> map = ...; ptr_vector<T> vec( map.begin(), map.end() ); -Thorsten
participants (2)
-
Oleg Smolsky
-
Thorsten Ottosen