Files
cppdraft_translate/cppdraft/string/require.md
2025-10-25 03:02:53 +03:00

3.2 KiB
Raw Blame History

[string.require]

27 Strings library [strings]

27.4 String classes [string.classes]

27.4.3 Class template basic_string [basic.string]

27.4.3.2 General requirements [string.require]

1

#

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

2

#

If any member function or operator of basic_string throws an exception, that function or operator has no other effect on the basic_string object.

3

#

Every object of typebasic_string<charT, traits, Allocator> uses an object of typeAllocator to allocate and free storage for the contained charT objects as needed.

The Allocator object used is obtained as described in [container.reqmts].

In every specialization basic_string<charT, traits, Allocator>, the type traits shall meet the character traits requirements ([char.traits]).

[Note 1:

Every specialization basic_string<charT, traits, Allocator> is an allocator-aware container ([container.alloc.reqmts]), but does not use the allocator's construct and destroy member functions ([container.requirements.pre]).

The program is ill-formed ifAllocator::value_type is not the same type as charT.

— end note]

[Note 2:

The program is ill-formed if traits::char_type is not the same type as charT.

— end note]

4

#

References, pointers, and iterators referring to the elements of abasic_string sequence may be invalidated by the following uses of that basic_string object:

  • (4.1)

    Passing as an argument to any standard library function taking a reference to non-constbasic_string as an argument.212

  • (4.2)

    Calling non-const member functions, exceptoperator[],at,data,front,back,begin,rbegin,end, andrend.

212)212)

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().