[string.modifiers] # 27 Strings library [[strings]](./#strings) ## 27.4 String classes [[string.classes]](string.classes#string.modifiers) ### 27.4.3 Class template basic_string [[basic.string]](basic.string#string.modifiers) #### 27.4.3.7 Modifiers [string.modifiers] #### [27.4.3.7.1](#string.op.append) basic_string​::​operator+= [[string.op.append]](string.op.append) [🔗](#lib:operator+=,basic_string) `constexpr basic_string& operator+=(const basic_string& str); ` [1](#string.op.append-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3178) *Effects*: Equivalent to: return append(str); [🔗](#lib:operator+=,basic_string_) `template constexpr basic_string& operator+=(const T& t); ` [2](#string.op.append-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3192) *Constraints*: - [(2.1)](#string.op.append-2.1) is_convertible_v> istrue and - [(2.2)](#string.op.append-2.2) is_convertible_v isfalse[.](#string.op.append-2.sentence-1) [3](#string.op.append-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3203) *Effects*: Equivalent to:basic_string_view sv = t;return append(sv); [🔗](#lib:operator+=,basic_string__) `constexpr basic_string& operator+=(const charT* s); ` [4](#string.op.append-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3218) *Effects*: Equivalent to: return append(s); [🔗](#lib:operator+=,basic_string___) `constexpr basic_string& operator+=(charT c); ` [5](#string.op.append-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3229) *Effects*: Equivalent to: return append(size_type{1}, c); [🔗](#lib:operator+=,basic_string____) `constexpr basic_string& operator+=(initializer_list il); ` [6](#string.op.append-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3240) *Effects*: Equivalent to: return append(il); #### [27.4.3.7.2](#string.append) basic_string​::​append [[string.append]](string.append) [🔗](#lib:append,basic_string) `constexpr basic_string& append(const basic_string& str); ` [1](#string.append-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3254) *Effects*: Equivalent to: return append(str.data(), str.size()); [🔗](#lib:append,basic_string_) `constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos); ` [2](#string.append-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3265) *Effects*: Equivalent to:return append(basic_string_view(str).substr(pos, n)); [🔗](#lib:append,basic_string__) `template constexpr basic_string& append(const T& t); ` [3](#string.append-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3280) *Constraints*: - [(3.1)](#string.append-3.1) is_convertible_v> istrue and - [(3.2)](#string.append-3.2) is_convertible_v isfalse[.](#string.append-3.sentence-1) [4](#string.append-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3291) *Effects*: Equivalent to:basic_string_view sv = t;return append(sv.data(), sv.size()); [🔗](#lib:append,basic_string___) `template constexpr basic_string& append(const T& t, size_type pos, size_type n = npos); ` [5](#string.append-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3307) *Constraints*: - [(5.1)](#string.append-5.1) is_convertible_v> istrue and - [(5.2)](#string.append-5.2) is_convertible_v isfalse[.](#string.append-5.sentence-1) [6](#string.append-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3318) *Effects*: Equivalent to:basic_string_view sv = t;return append(sv.substr(pos, n)); [🔗](#lib:append,basic_string____) `constexpr basic_string& append(const charT* s, size_type n); ` [7](#string.append-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3333) *Preconditions*: [s, s + n) is a valid range[.](#string.append-7.sentence-1) [8](#string.append-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3337) *Effects*: Appends a copy of the range [s, s + n) to the string[.](#string.append-8.sentence-1) [9](#string.append-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3341) *Returns*: *this[.](#string.append-9.sentence-1) [🔗](#lib:append,basic_string_____) `constexpr basic_string& append(const charT* s); ` [10](#string.append-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3352) *Effects*: Equivalent to: return append(s, traits​::​length(s)); [🔗](#lib:append,basic_string______) `constexpr basic_string& append(size_type n, charT c); ` [11](#string.append-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3363) *Effects*: Appends n copies of c to the string[.](#string.append-11.sentence-1) [12](#string.append-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3367) *Returns*: *this[.](#string.append-12.sentence-1) [🔗](#lib:append,basic_string_______) `template constexpr basic_string& append(InputIterator first, InputIterator last); ` [13](#string.append-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3379) *Constraints*: InputIterator is a type that qualifies as an input iterator ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements"))[.](#string.append-13.sentence-1) [14](#string.append-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3384) *Effects*: Equivalent to: return append(basic_string(first, last, get_allocator())); [🔗](#lib:append_range,basic_string) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr basic_string& append_range(R&& rg); ` [15](#string.append-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3396) *Effects*: Equivalent to: return append(basic_string(from_range, std​::​forward(rg), get_allocator())); [🔗](#lib:append,basic_string________) `constexpr basic_string& append(initializer_list il); ` [16](#string.append-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3407) *Effects*: Equivalent to: return append(il.begin(), il.size()); [🔗](#lib:push_back,basic_string) `constexpr void push_back(charT c); ` [17](#string.append-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3418) *Effects*: Equivalent toappend(size_type{1}, c)[.](#string.append-17.sentence-1) #### [27.4.3.7.3](#string.assign) basic_string​::​assign [[string.assign]](string.assign) [🔗](#lib:assign,basic_string) `constexpr basic_string& assign(const basic_string& str); ` [1](#string.assign-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3432) *Effects*: Equivalent to: return *this = str; [🔗](#lib:assign,basic_string_) `constexpr basic_string& assign(basic_string&& str) noexcept(allocator_traits::propagate_on_container_move_assignment::value || allocator_traits::is_always_equal::value); ` [2](#string.assign-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3445) *Effects*: Equivalent to: return *this = std​::​move(str); [🔗](#lib:assign,basic_string__) `constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos); ` [3](#string.assign-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3457) *Effects*: Equivalent to:return assign(basic_string_view(str).substr(pos, n)); [🔗](#lib:assign,basic_string___) `template constexpr basic_string& assign(const T& t); ` [4](#string.assign-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3472) *Constraints*: - [(4.1)](#string.assign-4.1) is_convertible_v> istrue and - [(4.2)](#string.assign-4.2) is_convertible_v isfalse[.](#string.assign-4.sentence-1) [5](#string.assign-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3483) *Effects*: Equivalent to:basic_string_view sv = t;return assign(sv.data(), sv.size()); [🔗](#lib:assign,basic_string____) `template constexpr basic_string& assign(const T& t, size_type pos, size_type n = npos); ` [6](#string.assign-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3499) *Constraints*: - [(6.1)](#string.assign-6.1) is_convertible_v> istrue and - [(6.2)](#string.assign-6.2) is_convertible_v isfalse[.](#string.assign-6.sentence-1) [7](#string.assign-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3510) *Effects*: Equivalent to:basic_string_view sv = t;return assign(sv.substr(pos, n)); [🔗](#lib:assign,basic_string_____) `constexpr basic_string& assign(const charT* s, size_type n); ` [8](#string.assign-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3525) *Preconditions*: [s, s + n) is a valid range[.](#string.assign-8.sentence-1) [9](#string.assign-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3529) *Effects*: Replaces the string controlled by *this with a copy of the range [s, s + n)[.](#string.assign-9.sentence-1) [10](#string.assign-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3534) *Returns*: *this[.](#string.assign-10.sentence-1) [🔗](#lib:assign,basic_string______) `constexpr basic_string& assign(const charT* s); ` [11](#string.assign-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3545) *Effects*: Equivalent to: return assign(s, traits​::​length(s)); [🔗](#lib:assign,basic_string_______) `constexpr basic_string& assign(initializer_list il); ` [12](#string.assign-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3556) *Effects*: Equivalent to: return assign(il.begin(), il.size()); [🔗](#lib:assign,basic_string________) `constexpr basic_string& assign(size_type n, charT c); ` [13](#string.assign-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3567) *Effects*: Equivalent to:clear(); resize(n, c);return *this; [🔗](#lib:assign,basic_string_________) `template constexpr basic_string& assign(InputIterator first, InputIterator last); ` [14](#string.assign-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3584) *Constraints*: InputIterator is a type that qualifies as an input iterator ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements"))[.](#string.assign-14.sentence-1) [15](#string.assign-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3589) *Effects*: Equivalent to: return assign(basic_string(first, last, get_allocator())); [🔗](#lib:assign_range,basic_string) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr basic_string& assign_range(R&& rg); ` [16](#string.assign-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3601) *Effects*: Equivalent to: return assign(basic_string(from_range, std​::​forward(rg), get_allocator())); #### [27.4.3.7.4](#string.insert) basic_string​::​insert [[string.insert]](string.insert) [🔗](#lib:insert,basic_string) `constexpr basic_string& insert(size_type pos, const basic_string& str); ` [1](#string.insert-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3614) *Effects*: Equivalent to: return insert(pos, str.data(), str.size()); [🔗](#lib:insert,basic_string_) `constexpr basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos); ` [2](#string.insert-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3626) *Effects*: Equivalent to:return insert(pos1, basic_string_view(str), pos2, n); [🔗](#lib:insert,basic_string__) `template constexpr basic_string& insert(size_type pos, const T& t); ` [3](#string.insert-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3641) *Constraints*: - [(3.1)](#string.insert-3.1) is_convertible_v> istrue and - [(3.2)](#string.insert-3.2) is_convertible_v isfalse[.](#string.insert-3.sentence-1) [4](#string.insert-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3652) *Effects*: Equivalent to:basic_string_view sv = t;return insert(pos, sv.data(), sv.size()); [🔗](#lib:insert,basic_string___) `template constexpr basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n = npos); ` [5](#string.insert-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3669) *Constraints*: - [(5.1)](#string.insert-5.1) is_convertible_v> istrue and - [(5.2)](#string.insert-5.2) is_convertible_v isfalse[.](#string.insert-5.sentence-1) [6](#string.insert-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3680) *Effects*: Equivalent to:basic_string_view sv = t;return insert(pos1, sv.substr(pos2, n)); [🔗](#lib:insert,basic_string____) `constexpr basic_string& insert(size_type pos, const charT* s, size_type n); ` [7](#string.insert-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3695) *Preconditions*: [s, s + n) is a valid range[.](#string.insert-7.sentence-1) [8](#string.insert-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3699) *Effects*: Inserts a copy of the range [s, s + n) immediately before the character at position pos if pos < size(), or otherwise at the end of the string[.](#string.insert-8.sentence-1) [9](#string.insert-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3705) *Returns*: *this[.](#string.insert-9.sentence-1) [10](#string.insert-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3709) *Throws*: - [(10.1)](#string.insert-10.1) out_of_range if pos > size(), - [(10.2)](#string.insert-10.2) length_error if n > max_size() - size(), or - [(10.3)](#string.insert-10.3) any exceptions thrown by allocator_traits​::​allocate[.](#string.insert-10.sentence-1) [🔗](#lib:insert,basic_string_____) `constexpr basic_string& insert(size_type pos, const charT* s); ` [11](#string.insert-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3724) *Effects*: Equivalent to: return insert(pos, s, traits​::​length(s)); [🔗](#lib:insert,basic_string______) `constexpr basic_string& insert(size_type pos, size_type n, charT c); ` [12](#string.insert-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3735) *Effects*: Inserts n copies of c before the character at position pos if pos < size(), or otherwise at the end of the string[.](#string.insert-12.sentence-1) [13](#string.insert-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3741) *Returns*: *this[.](#string.insert-13.sentence-1) [14](#string.insert-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3745) *Throws*: - [(14.1)](#string.insert-14.1) out_of_range if pos > size(), - [(14.2)](#string.insert-14.2) length_error if n > max_size() - size(), or - [(14.3)](#string.insert-14.3) any exceptions thrown by allocator_traits​::​allocate[.](#string.insert-14.sentence-1) [🔗](#lib:insert,basic_string_______) `constexpr iterator insert(const_iterator p, charT c); ` [15](#string.insert-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3760) *Preconditions*: p is a valid iterator on*this[.](#string.insert-15.sentence-1) [16](#string.insert-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3765) *Effects*: Inserts a copy of c at the position p[.](#string.insert-16.sentence-1) [17](#string.insert-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3769) *Returns*: An iterator which refers to the inserted character[.](#string.insert-17.sentence-1) [🔗](#lib:insert,basic_string________) `constexpr iterator insert(const_iterator p, size_type n, charT c); ` [18](#string.insert-18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3780) *Preconditions*: p is a valid iterator on*this[.](#string.insert-18.sentence-1) [19](#string.insert-19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3785) *Effects*: Inserts n copies of c at the position p[.](#string.insert-19.sentence-1) [20](#string.insert-20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3789) *Returns*: An iterator which refers to the first inserted character, orp if n == 0[.](#string.insert-20.sentence-1) [🔗](#lib:insert,basic_string_________) `template constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last); ` [21](#string.insert-21) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3802) *Constraints*: InputIterator is a type that qualifies as an input iterator ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements"))[.](#string.insert-21.sentence-1) [22](#string.insert-22) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3807) *Preconditions*: p is a valid iterator on*this[.](#string.insert-22.sentence-1) [23](#string.insert-23) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3812) *Effects*: Equivalent toinsert(p - begin(), basic_string(first, last, get_allocator()))[.](#string.insert-23.sentence-1) [24](#string.insert-24) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3817) *Returns*: An iterator which refers to the first inserted character, orp if first == last[.](#string.insert-24.sentence-1) [🔗](#lib:insert_range,basic_string) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr iterator insert_range(const_iterator p, R&& rg); ` [25](#string.insert-25) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3830) *Preconditions*: p is a valid iterator on *this[.](#string.insert-25.sentence-1) [26](#string.insert-26) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3834) *Effects*: Equivalent toinsert(p - begin(), basic_string(from_range, std​::​forward(rg), get_allocator()))[.](#string.insert-26.sentence-1) [27](#string.insert-27) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3839) *Returns*: An iterator which refers to the first inserted character, orp if rg is empty[.](#string.insert-27.sentence-1) [🔗](#lib:insert,basic_string__________) `constexpr iterator insert(const_iterator p, initializer_list il); ` [28](#string.insert-28) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3851) *Effects*: Equivalent to: return insert(p, il.begin(), il.end()); #### [27.4.3.7.5](#string.erase) basic_string​::​erase [[string.erase]](string.erase) [🔗](#lib:erase,basic_string) `constexpr basic_string& erase(size_type pos = 0, size_type n = npos); ` [1](#string.erase-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3864) *Effects*: Determines the effective length xlen of the string to be removed as the smaller of n andsize() - pos[.](#string.erase-1.sentence-1) Removes the characters in the range [begin() + pos, begin() + pos + xlen)[.](#string.erase-1.sentence-2) [2](#string.erase-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3871) *Returns*: *this[.](#string.erase-2.sentence-1) [3](#string.erase-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3875) *Throws*: out_of_range if pos> size()[.](#string.erase-3.sentence-1) [🔗](#lib:erase,basic_string_) `constexpr iterator erase(const_iterator p); ` [4](#string.erase-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3888) *Preconditions*: p is a valid dereferenceable iterator on *this[.](#string.erase-4.sentence-1) [5](#string.erase-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3892) *Effects*: Removes the character referred to by p[.](#string.erase-5.sentence-1) [6](#string.erase-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3896) *Returns*: An iterator which points to the element immediately following p prior to the element being erased[.](#string.erase-6.sentence-1) If no such element exists,end() is returned[.](#string.erase-6.sentence-2) [7](#string.erase-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3904) *Throws*: Nothing[.](#string.erase-7.sentence-1) [🔗](#lib:erase,basic_string__) `constexpr iterator erase(const_iterator first, const_iterator last); ` [8](#string.erase-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3915) *Preconditions*: first and last are valid iterators on*this[.](#string.erase-8.sentence-1) [first, last) is a valid range[.](#string.erase-8.sentence-2) [9](#string.erase-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3920) *Effects*: Removes the characters in the range [first, last)[.](#string.erase-9.sentence-1) [10](#string.erase-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3925) *Returns*: An iterator which points to the element pointed to by last prior to the other elements being erased[.](#string.erase-10.sentence-1) If no such element exists,end() is returned[.](#string.erase-10.sentence-2) [11](#string.erase-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3933) *Throws*: Nothing[.](#string.erase-11.sentence-1) [🔗](#lib:pop_back,basic_string) `constexpr void pop_back(); ` [12](#string.erase-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3944) *Hardened preconditions*: empty() is false[.](#string.erase-12.sentence-1) [13](#string.erase-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3948) *Effects*: Equivalent to erase(end() - 1)[.](#string.erase-13.sentence-1) [14](#string.erase-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3952) *Throws*: Nothing[.](#string.erase-14.sentence-1) #### [27.4.3.7.6](#string.replace) basic_string​::​replace [[string.replace]](string.replace) [🔗](#lib:replace,basic_string) `constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str); ` [1](#string.replace-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3965) *Effects*: Equivalent to: return replace(pos1, n1, str.data(), str.size()); [🔗](#lib:replace,basic_string_) `constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos); ` [2](#string.replace-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3977) *Effects*: Equivalent to:return replace(pos1, n1, basic_string_view(str).substr(pos2, n2)); [🔗](#lib:replace,basic_string__) `template constexpr basic_string& replace(size_type pos1, size_type n1, const T& t); ` [3](#string.replace-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L3992) *Constraints*: - [(3.1)](#string.replace-3.1) is_convertible_v> istrue and - [(3.2)](#string.replace-3.2) is_convertible_v isfalse[.](#string.replace-3.sentence-1) [4](#string.replace-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4003) *Effects*: Equivalent to:basic_string_view sv = t;return replace(pos1, n1, sv.data(), sv.size()); [🔗](#lib:replace,basic_string___) `template constexpr basic_string& replace(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos); ` [5](#string.replace-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4020) *Constraints*: - [(5.1)](#string.replace-5.1) is_convertible_v> istrue and - [(5.2)](#string.replace-5.2) is_convertible_v isfalse[.](#string.replace-5.sentence-1) [6](#string.replace-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4031) *Effects*: Equivalent to:basic_string_view sv = t;return replace(pos1, n1, sv.substr(pos2, n2)); [🔗](#lib:replace,basic_string____) `constexpr basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2); ` [7](#string.replace-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4046) *Preconditions*: [s, s + n2) is a valid range[.](#string.replace-7.sentence-1) [8](#string.replace-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4050) *Effects*: Determines the effective length xlen of the string to be removed as the smaller of n1 and size() - pos1[.](#string.replace-8.sentence-1) Ifsize() - xlen >= max_size() - n2 throws length_error[.](#string.replace-8.sentence-2) Otherwise, the function replaces the characters in the range [begin() + pos1, begin() + pos1 + xlen) with a copy of the range [s, s + n2)[.](#string.replace-8.sentence-3) [9](#string.replace-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4059) *Returns*: *this[.](#string.replace-9.sentence-1) [10](#string.replace-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4063) *Throws*: - [(10.1)](#string.replace-10.1) out_of_range if pos1 > size(), - [(10.2)](#string.replace-10.2) length_error if the length of the resulting string would exceed max_size(), or - [(10.3)](#string.replace-10.3) any exceptions thrown by allocator_traits​::​allocate[.](#string.replace-10.sentence-1) [🔗](#lib:replace,basic_string_____) `constexpr basic_string& replace(size_type pos, size_type n, const charT* s); ` [11](#string.replace-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4079) *Effects*: Equivalent to: return replace(pos, n, s, traits​::​length(s)); [🔗](#lib:replace,basic_string______) `constexpr basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c); ` [12](#string.replace-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4090) *Effects*: Determines the effective length xlen of the string to be removed as the smaller of n1 and size() - pos1[.](#string.replace-12.sentence-1) Ifsize() - xlen >= max_size() - n2 throws length_error[.](#string.replace-12.sentence-2) Otherwise, the function replaces the characters in the range [begin() + pos1, begin() + pos1 + xlen) with n2 copies of c[.](#string.replace-12.sentence-3) [13](#string.replace-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4099) *Returns*: *this[.](#string.replace-13.sentence-1) [14](#string.replace-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4103) *Throws*: - [(14.1)](#string.replace-14.1) out_of_range if pos1 > size(), - [(14.2)](#string.replace-14.2) length_error if the length of the resulting string would exceed max_size(), or - [(14.3)](#string.replace-14.3) any exceptions thrown by allocator_traits​::​allocate. [🔗](#lib:replace,basic_string_______) `constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); ` [15](#string.replace-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4119) *Effects*: Equivalent to: return replace(i1, i2, basic_string_view(str)); [🔗](#lib:replace,basic_string________) `template constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t); ` [16](#string.replace-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4131) *Constraints*: - [(16.1)](#string.replace-16.1) is_convertible_v> istrue and - [(16.2)](#string.replace-16.2) is_convertible_v isfalse[.](#string.replace-16.sentence-1) [17](#string.replace-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4142) *Preconditions*: [begin(), i1) and [i1, i2) are valid ranges[.](#string.replace-17.sentence-1) [18](#string.replace-18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4146) *Effects*: Equivalent to:basic_string_view sv = t;return replace(i1 - begin(), i2 - i1, sv.data(), sv.size()); [🔗](#lib:replace,basic_string_________) `constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n); ` [19](#string.replace-19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4161) *Effects*: Equivalent to: return replace(i1, i2, basic_string_view(s, n)); [🔗](#lib:replace,basic_string__________) `constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s); ` [20](#string.replace-20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4172) *Effects*: Equivalent to: return replace(i1, i2, basic_string_view(s)); [🔗](#lib:replace,basic_string___________) `constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c); ` [21](#string.replace-21) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4183) *Preconditions*: [begin(), i1) and [i1, i2) are valid ranges[.](#string.replace-21.sentence-1) [22](#string.replace-22) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4187) *Effects*: Equivalent to: return replace(i1 - begin(), i2 - i1, n, c); [🔗](#lib:replace,basic_string____________) `template constexpr basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); ` [23](#string.replace-23) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4200) *Constraints*: InputIterator is a type that qualifies as an input iterator ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements"))[.](#string.replace-23.sentence-1) [24](#string.replace-24) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4205) *Effects*: Equivalent to: return replace(i1, i2, basic_string(j1, j2, get_allocator())); [🔗](#lib:replace_with_range,basic_string) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr basic_string& replace_with_range(const_iterator i1, const_iterator i2, R&& rg); ` [25](#string.replace-25) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4217) *Effects*: Equivalent to:return replace(i1, i2, basic_string(from_range, std::forward(rg), get_allocator())); [🔗](#lib:replace,basic_string_____________) `constexpr basic_string& replace(const_iterator i1, const_iterator i2, initializer_list il); ` [26](#string.replace-26) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4231) *Effects*: Equivalent to: return replace(i1, i2, il.begin(), il.size()); #### [27.4.3.7.7](#string.copy) basic_string​::​copy [[string.copy]](string.copy) [🔗](#lib:copy,basic_string) `constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const; ` [1](#string.copy-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4244) *Effects*: Equivalent to:return basic_string_view(*this).copy(s, n, pos); [*Note [1](#string.copy-note-1)*: This does not terminate s with a null object[.](#string.copy-1.sentence-1) — *end note*] #### [27.4.3.7.8](#string.swap) basic_string​::​swap [[string.swap]](string.swap) [🔗](#lib:swap,basic_string) `constexpr void swap(basic_string& s) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); ` [1](#string.swap-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4263) *Preconditions*: allocator_traits​::​propagate_on_container_swap​::​value is true orget_allocator() == s.get_allocator()[.](#string.swap-1.sentence-1) [2](#string.swap-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4269) *Postconditions*: *this contains the same sequence of characters that was in s,s contains the same sequence of characters that was in*this[.](#string.swap-2.sentence-1) [3](#string.swap-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4276) *Throws*: Nothing[.](#string.swap-3.sentence-1) [4](#string.swap-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4280) *Complexity*: Constant time[.](#string.swap-4.sentence-1)