Const iterators

  • Thread starter Christian Chrismann
  • Start date
C

Christian Chrismann

Hi,

someone told me that STL const_iterators are faster than non-const
iterators. Is this really true? And if so, why?

I though that const_iterators should be used when possible in
order to avoid side effects (no accidental writes). But I never heard
of a speed-up.

Regards,
Chris
 
P

Pierre Barbier de Reuille

Christian said:
Hi,

someone told me that STL const_iterators are faster than non-const
iterators. Is this really true? And if so, why?

I though that const_iterators should be used when possible in
order to avoid side effects (no accidental writes). But I never heard
of a speed-up.

Regards,
Chris

for a good answer:

http://www.gotw.ca/gotw/081.htm

very nice writing :)

Pierre
 
P

Pierre Barbier de Reuille

Christian said:
Hi,

someone told me that STL const_iterators are faster than non-const
iterators. Is this really true? And if so, why?

I though that const_iterators should be used when possible in
order to avoid side effects (no accidental writes). But I never heard
of a speed-up.

Regards,
Chris

I forgot ... the short answer is "no, it is not quicker to run", the
long answer is in the article.

Pierre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top