Re: Question about STL iterator usage
"Colin" <razael1@gmail.com> wrote in message
news:1153075967.182391.281300@p79g2000cwp.googlegroups.com...
I've noticed that when working with iterators, most people will use
"(*i).memberFunc()" rather than "i->memberFunc()". Is this simply a
stylistic preference or is there a practical reason to use one and not
the other?
Once upon a time, compilers could instantiate all template class
member functions whether or not they were called. So it wasn't
safe to define operator->() for, say, a templatized iterator class
if the elements it designated could be scalars instead of class
objects. Midway through C++ standardization the instantiation rules
made clear that the compiler should not fuss with any member
functions that never got called. It took several years after that
ruling before most compilers fell into line.
Thus, it has always been safe to write (*i).memberFunc() but only
recently safe to write i->memberFunc(). Those of us who have to
live with a broad range of compilers still favor the first form,
out of prudence.
HTH,
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]