template< class Operation >
constexpr void resize_and_overwrite( size_type count, Operation op );
Resizes the string to contain at most
count characters, using the user-provided operation
op to modify the possibly indeterminate contents and set the length.
This function performs following steps:
- Obtains a contiguous storage that contains count + 1 characters, and makes its first
kcharacter equal to the first
kcharacters of *this, where
kis the smaller of
countand the result of this->size() before the call to
pdenote the pointer to the first character in the storage.
- The equality is determined as if by checking this->compare(0, k, p, k) == 0.
- The characters in
[p + k, p + count]may have indeterminate values.
- Evaluates std::move(op)(p, count). Let
rbe the return value of std::move(op)(p, count).
- Replaces the contents of *this with
[p, p + r)(which sets the length of *this to
r). Invalidates all pointers and references to the range
[p, p + count].
The program is ill-formed if
r does not have an integer-like type. The behavior is undefined if std::move(op)(p, count) throws an exception or modifies
r is not in the range
[0, count], or any character in range
[p, p + r) has an indeterminate value.
Implementations are recommended to avoid unnecessary copies and allocations by, e.g., making
p equal to the pointer to beginning of storage of characters allocated for *this after the call, which can be identical to the existing storage of *this if
count is less than or equal to this->capacity().
|count||-||the maximal possible new size of the string|
|op||-||the function object used for setting the new contents of the string|
 Return value
std::length_error if count > max_size().
Any exceptions thrown by corresponding
If an exception is thrown from std::move(op)(p, count), the behavior is undefined. Otherwise, if an exception is thrown, this function has no effect.
resize_and_overwrite invalidates all iterators, pointers, and references into *this, regardless whether reallocation occurs. Implementations may assume that the contents of the string are not aliased after the call to
|This section is incomplete|
Reason: no example
 See also
| changes the number of characters stored |
(public member function)
| creates a unique pointer that manages a new object |
| creates a shared pointer that manages a new object |
| creates a shared pointer that manages a new object allocated using an allocator |