21 Strings library [strings]

21.4 Class template basic_string [basic.string]

21.4.1 basic_string general requirements [string.require]

If any operation would cause size() to exceed max_size(), that operation shall throw an exception object of type length_error.

If any member function or operator of basic_string throws an exception, that function or operator shall have no other effect.

No erase() or pop_back() member function shall throw any exceptions.

In every specialization basic_string<charT, traits, Allocator>, the type allocator_traits<Allocator>::value_type shall name the same type as charT. Every object of type basic_string<charT, traits, Allocator> shall use an object of type Allocator to allocate and free storage for the contained charT objects as needed. The Allocator object used shall be obtained as described in [container.requirements.general].

The char-like objects in a basic_string object shall be stored contiguously. That is, for any basic_string object s, the identity &*(s.begin() + n) == &*s.begin() + n shall hold for all values of n such that 0 <= n < s.size().

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 any standard library function taking a reference to non-const basic_string as an argument.235

  • Calling non-const member functions, except operator[], at, front, back, begin, rbegin, end, and rend.

For example, as an argument to non-member functions swap() ([string.special]), operator>>() ([string.io]), and getline() ([string.io]), or as an argument to basic_string::swap()