I read something from "More Effective C++", item 18:
In brief, the iterator it is an object, not a pointer, so there is no guarantee that “->” can be applied to it.† The STL does require that “.” and “*” be valid for iterators, however, so (*it).second, though syntactically clumsy, is guaranteed to work.)
Usually, I use ->
on iterators and there isn't any problem. Could anyone give a example or explain it?
"More Effective C++" is nearly 20 years old (published 1996); while an excellent book, it should be read with an awareness of its historical context.
In the 2003 version of the Standard (itself over 10 years old) iterators are required to support ->
([lib.iterator.requirements]/1):
[...] All iterators
i
for which the expression(*i).m
is well-defined, support the expressioni->m
with the same semantics as(*i).m.
[...]
You would only need to write (*i).m
when working with an archaic implementation with non-compliant "standard" libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With