0

Is it legal to make snapshots of const_iterator from the std::string class without invalidating it when performing ++ operations.

For example: If want to save the position in a string so I copy the current const_iterator:

std::string::const_iterator it = prev;

Now my parser continues with prev++. Is it still valid and points to the previous position of prev?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Gustavo
  • 919
  • 11
  • 34
  • 4
    @alirakiyan Because that won't tell him what's guaranteed to happen. Sure, if it doesn't work, he knows it's useless. But if it does work, he knows nothing -- it may or may not be safe/legal/guaranteed. – David Schwartz May 27 '17 at 11:01

1 Answers1

3

Is it still valid and points to the previous position of prev?

Yes, as long the std::string isn't changed (in ways other than operator[] or at()) that's legal and the iterator snapshot is still valid.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190