Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext
basic_static_string::replace (4 of 14 overloads)

Replace a part of the string.

Synopsis
template<
    typename T>
constexpr basic_static_string&
replace(
    size_type pos1,
    size_type n1,
    const T& t,
    size_type pos2,
    size_type n2 = npos);
Description

Constructs a temporary string_view_type object sv from t, and replaces rcount characters starting at index pos1 with those of sv.substr(pos2, n2), where rcount is std::min(n1, size() - pos).

Exception Safety

Strong guarantee.

Remarks

All references, pointers, or iterators referring to contained elements are invalidated. Any past-the-end iterators are also invalidated.

Template Parameters

Type

Description

T

The type of the object to convert.

Constraints

stdis_convertible<const T&, string_view>::value && !stdis_convertible<const T&, const CharT*>::value && !stdis_convertible<const T&, const basic_static_string&>::value.

Return Value

*this

Parameters

Name

Description

pos1

The index to replace at.

n1

The number of characters to replace.

t

The object to replace with.

pos2

The index to begin the substring.

n2

The length of the substring. The default argument for this parameter is npos.

Exceptions

Type

Thrown On

std::length_error

size() + (std::min(n2, sv.size()) - rcount) > max_size()

std::out_of_range

pos1 > size()

std::out_of_range

pos2 > sv.size()


PrevUpHomeNext