You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

The basic_string template class has unusual invalidation semantics. References, pointers, and iterators referring to the elements of a basic_string sequence may be invalidated by the following uses of that basic_string object:

  • As an argument to non-member functions swap(), operator>>(), and getline().
  • As an argument to basic_string::swap().
  • Calling data() and c_str() member functions.
  • Calling non-const member functions, except operator[](), at(), begin(), rbegin(), end(), and rend().

  • Subsequent to any of the above uses except the forms of insert() and erase() which return iterators, the first call to non-const member functions operator[](), at(), begin(), rbegin(), end(), or rend().

Non-Compliant Example

Compliant Example.

Exceptions

The intent of these iterator invalidation rules is to give implementors greater freedom in implementation techniques. Some implementations implement method version that do not invalidate references, pointers, and iterators in all cases. Check with your implementation specific documentation and document any violation of the semantics specified by the standard for portability.

References

  • No labels