STL question

R

Ron Natalie

Martin Eisenberg said:
Ron said:
You're only guaranteed to be able to apply operator[] to
random access iterators.

Does *(it + k) work with all iterators?

No, for other than random access iterators, you're limited bumping
it forward with ++. You can't add an arbitrary integer.
 
J

Jeff Flinn

Martin Eisenberg said:
Ron said:
You're only guaranteed to be able to apply operator[] to
random access iterators.

Does *(it + k) work with all iterators?

No, but "std::advance( it, k );" does. Note that it will modify "it".
std::advance is(usually) specialized for the various iterator categories,
using the most appropriate method to increment by k.

Jeff F
 

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

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top