absl::StringResizeAndOverwrite

Resizes str to contain at most n characters, using the user-provided operation op to modify the possibly indeterminate contents. op must return the finalized length of str.

Synopsis

Declared in <absl/strings/resize_and_overwrite.h>

template<
    typename T,
    typename Op>
void
StringResizeAndOverwrite(
    T& str,
    T::size_type n,
    Op op);

Description

Invalidates all iterators, pointers, and references into str, regardless of whether reallocation occurs.

op(value_type* buf, size_t buf_size) is allowed to write value_type{} to buf[buf_size], which facilitiates interoperation with functions that write a trailing NUL. Please note that this requirement is more strict than basic_string::resize_and_overwrite(), which allows writing an abitrary value to buf[buf_size].

Parameters

NameDescription
strThe string to resize and overwrite.
nThe maximum number of characters str will contain.
opThe operation used to modify the contents of str.