STD::WSTRING(3)

πŸŽ€ NAME πŸŽ€

okay so first things first, bestie: this page is std::basic_string< _CharT, _Traits, _Alloc >(3), and it lives in the Library Functions Manual. yes the title line up top is all cryptic and truncated like std::basic..., _Alloc >(3) β€” that's just the header being dramatic, we know who she is πŸ’…

What does she do? Managing sequences of characters and character-like objects. That's it. That's the whole job. And she does it iconically.

🫢 heads up: this manual is LONG, like 19 parts long, and you're reading part 1 right now. Don't panic. We're gonna get through it together.

✨ SYNOPSIS ✨

First, the summoning ritual:

#include <string>

That's the include. That's the whole spell. Say it with me: #include <string> 🌸


🌈 Inherited by

She's not alone in this world, and these little ones carry her DNA:

  • __gnu_debug::basic_string< char >
  • __gnu_debug::basic_string< wchar_t >
  • __gnu_debug::basic_string< char16_t >
  • __gnu_debug::basic_string< char32_t >
  • __gnu_debug::basic_string< _CharT, _Traits, _Allocator >

no cap, that last one is literally her but with a different allocator name spelled out. the family resemblance is real 😭


πŸ’– Public Types πŸ’–

okay so this is the part where the page just dumps the whole type zoo on you, and ngl a bunch of these show up twice β€” same name, two different underlying recipes. That's not a typo, that's just how the page lists them, so I'm giving you every single one, in order, no skips, no shortcuts. periodt πŸ’…

  • typedef _Char_alloc_type allocator_type β€” the allocator type, first version, handed to you under the name allocator_type.
  • typedef _Alloc allocator_type β€” and here's allocator_type again, defined off _Alloc this time. yes, same name. she contains multitudes.
  • typedef __gnu_cxx::__normal_iterator< const_pointer, basic_string > const_iterator β€” a const_iterator built from __gnu_cxx::__normal_iterator< const_pointer, basic_string >. read-only energy, we love her πŸ¦‹
  • typedef __gnu_cxx::__normal_iterator< const_pointer, basic_string > const_iterator β€” same thing, listed again. the page said it twice and I respect the commitment.
  • typedef _Alloc_traits::const_pointer const_pointer β€” const_pointer, defined off _Alloc_traits::const_pointer.
  • typedef _CharT_alloc_traits::const_pointer const_pointer β€” and const_pointer again, this time off _CharT_alloc_traits::const_pointer.
  • typedef _Alloc_traits::const_reference const_reference β€” const_reference, from _Alloc_traits::const_reference.
  • typedef const value_type & const_reference β€” const_reference again, and this one is literally const value_type &. very demure, very direct.
  • typedef std::reverse_iterator< const_iterator > const_reverse_iterator β€” const_reverse_iterator, aka a const_iterator that walks backwards. main character walking into the room backwards just to be extra ✨
  • typedef std::reverse_iterator< const_iterator > const_reverse_iterator β€” same one, second appearance. she said it twice because it slaps.
  • typedef _Alloc_traits::difference_type difference_type β€” difference_type, from _Alloc_traits::difference_type.
  • typedef _CharT_alloc_traits::difference_type difference_type β€” difference_type again, from _CharT_alloc_traits::difference_type.
  • typedef __gnu_cxx::__normal_iterator< pointer, basic_string > iterator β€” iterator, built from __gnu_cxx::__normal_iterator< pointer, basic_string >. now you can actually change stuff πŸ‘‘
  • typedef __gnu_cxx::__normal_iterator< pointer, basic_string > iterator β€” listed again, same definition. consistency queen.
  • typedef _Alloc_traits::pointer pointer β€” pointer, from _Alloc_traits::pointer.
  • typedef _CharT_alloc_traits::pointer pointer β€” pointer again, from _CharT_alloc_traits::pointer.
  • typedef _Alloc_traits::reference reference β€” reference, from _Alloc_traits::reference.
  • typedef value_type & reference β€” reference again, and it's just value_type &. short, sweet, gets the job done πŸ’œ
  • typedef std::reverse_iterator< iterator > reverse_iterator β€” reverse_iterator, a reverse_iterator wrapped around iterator. backwards but make it editable.
  • typedef std::reverse_iterator< iterator > reverse_iterator β€” yep, the same one again. two for two πŸŽ€
  • typedef _Alloc_traits::size_type size_type β€” size_type, from _Alloc_traits::size_type. sizes! lengths! the math of it all!
  • typedef _CharT_alloc_traits::size_type size_type β€” size_type again, from _CharT_alloc_traits::size_type.
  • typedef _Traits traits_type β€” traits_type, which is _Traits. she's literally the traits template param, wearing a lil name tag 🏷️
  • typedef _Traits traits_type β€” same, second time. the page really said "and you're gonna hear it again."
  • typedef _Traits::char_type value_type β€” value_type, from _Traits::char_type. this is the thing all the strings are made of πŸ’–
  • typedef _Traits::char_type value_type β€” and value_type once more, identical. okay we get it, she's important 😭

and that's the type list, every last one, nothing skipped, nothing merged, no invented lore. there's a LOT more of this page coming, bestie β€” 18 more parts β€” so keep your #include <string> warm 🫢

πŸ’– Public Member Functions πŸ’–

okay bestie, this is the member function roster and it's giving main character energy. every single signature is copied exactly β€” constexpr twins, allocator overloads, deleted stuff, all of it. no skipping, no summarising, periodt.

  • basic_string () noexcept β€” default constructor creates an empty string. iconic.
  • constexpr basic_string () noexcept(/*conditional */) β€” default constructor creates an empty string. the constexpr version said "let me glow too."
  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc()) β€” construct string as copy of a range. range vibes.
  • template<class _InputIterator> basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc()) β€” construct string as copy of a range. the non-constexpr one is here too.
  • constexpr basic_string (basic_string &&__str) noexcept β€” move construct string. move it, move it.
  • basic_string (basic_string &&__str) noexcept β€” move construct string. yes, the non-constexpr twin.
  • basic_string (basic_string &&__str, const _Alloc &__a) β€” no description in the original, bestie. we're not inventing lore.
  • constexpr basic_string (basic_string &&__str, const _Alloc &__a) noexcept(_Alloc_traits::_S_always_equal()) β€” no description in the original. just the signature, slaying.
  • constexpr basic_string (basic_string &&__str, size_type __pos, const _Alloc &__a=_Alloc()) β€” no description in the original. mysterious.
  • constexpr basic_string (basic_string &&__str, size_type __pos, size_type __n, const _Alloc &__a=_Alloc()) β€” no description in the original. still iconic.
  • basic_string (const _Alloc &__a) β€” construct an empty string using allocator a. allocator core.
  • constexpr basic_string (const _Alloc &__a) noexcept β€” construct an empty string using allocator a. constexpr edition.
  • template<typename = _RequireAllocator<_Alloc>> constexpr basic_string (const _CharT *__s, const _Alloc &__a=_Alloc()) β€” construct string as copy of a C string. C string copy.
  • template<typename = _RequireAllocator<_Alloc>> basic_string (const _CharT *__s, const _Alloc &__a=_Alloc()) β€” construct string as copy of a C string. non-constexpr twin.
  • constexpr basic_string (const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc()) β€” construct string initialized by a character array. character array tea.
  • basic_string (const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc()) β€” construct string initialized by a character array. same but non-constexpr.
  • constexpr basic_string (const basic_string &__str) β€” construct string with copy of value of __str. copy that.
  • basic_string (const basic_string &__str) β€” construct string with copy of value of str. note the description says str, bestie, we keep it exact.
  • constexpr basic_string (const basic_string &__str, const _Alloc &__a) β€” no description in the original. just vibes.
  • basic_string (const basic_string &__str, const _Alloc &__a) β€” no description in the original. twin energy.
  • constexpr basic_string (const basic_string &__str, size_type __pos, const _Alloc &__a=_Alloc()) β€” construct string as copy of a substring. substring moment.
  • basic_string (const basic_string &__str, size_type __pos, const _Alloc &__a=_Alloc()) β€” construct string as copy of a substring. non-constexpr.
  • constexpr basic_string (const basic_string &__str, size_type __pos, size_type __n) β€” construct string as copy of a substring. more substring.
  • basic_string (const basic_string &__str, size_type __pos, size_type __n) β€” construct string as copy of a substring. yes.
  • constexpr basic_string (const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a) β€” construct string as copy of a substring. with allocator.
  • basic_string (const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a) β€” construct string as copy of a substring. non-constexpr with allocator.
  • constexpr basic_string (initializer_list< _CharT > __l, const _Alloc &__a=_Alloc()) β€” construct string from an initializer list. initializer list slay.
  • basic_string (initializer_list< _CharT > __l, const _Alloc &__a=_Alloc()) β€” construct string from an initializer list. non-constexpr twin.
  • basic_string (nullptr_t)=delete β€” no description in the original. it's deleted, so don't try it.
  • basic_string (nullptr_t)=delete β€” no description in the original. yes, it's listed twice, we keep both.
  • template<typename = _RequireAllocator<_Alloc>> constexpr basic_string (size_type __n, _CharT __c, const _Alloc &__a=_Alloc()) β€” construct string as multiple characters. multiple characters.
  • basic_string (size_type __n, _CharT __c, const _Alloc &__a=_Alloc()) β€” construct string as multiple characters. non-constexpr.
  • constexpr ~basic_string () β€” destroy the string instance. destruction, but make it couture.
  • ~basic_string () noexcept β€” destroy the string instance. noexcept edition.
  • template<typename _Operation> constexpr void __resize_and_overwrite (size_type __n, _Operation __op) β€” non-standard version of resize_and_overwrite for C++11 and above. non-standard but useful.
  • template<typename _Operation> void __resize_and_overwrite (size_type __n, _Operation __op) β€” non-standard version of resize_and_overwrite for C++11 and above. non-constexpr twin.
  • template<typename _InputIterator> basic_string< _CharT, _Traits, _Alloc > & _M_replace_dispatch (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2, __false_type) β€” no description in the original. internal dispatch tea.
  • template<typename _InIterator> _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, forward_iterator_tag) β€” no description in the original. internal construct tea.
  • template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & append (_InputIterator __first, _InputIterator __last) β€” append a range of characters. append szn.
  • template<class _InputIterator> basic_string & append (_InputIterator __first, _InputIterator __last) β€” append a range of characters. non-constexpr twin.
  • constexpr basic_string & append (const _CharT *__s) β€” append a C string. C string append.
  • basic_string & append (const _CharT *__s) β€” append a C string. non-constexpr.
  • constexpr basic_string & append (const _CharT *__s, size_type __n) β€” append a C substring. substring append.
  • basic_string & append (const _CharT *__s, size_type __n) β€” append a C substring. non-constexpr.
  • constexpr basic_string & append (const basic_string &__str) β€” append a string to this string. string to string.
  • basic_string & append (const basic_string &__str) β€” append a string to this string. non-constexpr.
  • constexpr basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos) β€” append a substring. substring append again.
  • basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos) β€” append a substring. non-constexpr.
  • constexpr basic_string & append (initializer_list< _CharT > __l) β€” append an initializer_list of characters. list append.
  • basic_string & append (initializer_list< _CharT > __l) β€” append an initializer_list of characters. non-constexpr.
  • constexpr basic_string & append (size_type __n, _CharT __c) β€” append multiple characters. multiple chars.
  • basic_string & append (size_type __n, _CharT __c) β€” append multiple characters. non-constexpr.
  • template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & assign (_InputIterator __first, _InputIterator __last) β€” set value to a range of characters. assign range.
  • template<class _InputIterator> basic_string & assign (_InputIterator __first, _InputIterator __last) β€” set value to a range of characters. non-constexpr.
  • constexpr basic_string & assign (basic_string &&__str) noexcept(_Alloc_traits::_S_nothrow_move()) β€” set value to contents of another string. move assign.
  • basic_string & assign (basic_string &&__str) noexcept(allocator_traits< _Alloc >::is_always_equal::value) β€” set value to contents of another string. non-constexpr move assign.
  • constexpr basic_string & assign (const _CharT *__s) β€” set value to contents of a C string. C string assign.
  • basic_string & assign (const _CharT *__s) β€” set value to contents of a C string. non-constexpr.
  • constexpr basic_string & assign (const _CharT *__s, size_type __n) β€” set value to a C substring. C substring assign.
  • basic_string & assign (const _CharT *__s, size_type __n) β€” set value to a C substring. non-constexpr.
  • constexpr basic_string & assign (const basic_string &__str) β€” set value to contents of another string. string assign.
  • basic_string & assign (const basic_string &__str) β€” set value to contents of another string. non-constexpr.
  • constexpr basic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos) β€” set value to a substring of a string. substring assign.
  • basic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos) β€” set value to a substring of a string. non-constexpr.
  • constexpr basic_string & assign (initializer_list< _CharT > __l) β€” set value to an initializer_list of characters. list assign.
  • basic_string & assign (initializer_list< _CharT > __l) β€” set value to an initializer_list of characters. non-constexpr.
  • constexpr basic_string & assign (size_type __n, _CharT __c) β€” set value to multiple characters. multiple chars assign.
  • basic_string & assign (size_type __n, _CharT __c) β€” set value to multiple characters. non-constexpr.
  • constexpr reference at (size_type __n) β€” provides access to the data contained in the string. access, bestie.
  • reference at (size_type __n) β€” provides access to the data contained in the string. non-constexpr.
  • constexpr const_reference at (size_type __n) const β€” provides access to the data contained in the string. const edition.
  • const_reference at (size_type __n) const β€” provides access to the data contained in the string. non-constexpr const edition.
  • reference back () β€” no description in the original. back access tea.
  • constexpr const_reference back () const noexcept β€” no description in the original. constexpr const back.
  • const_reference back () const noexcept β€” no description in the original. non-constexpr const back.
  • constexpr reference back () noexcept β€” no description in the original. constexpr back.
  • iterator begin () β€” no description in the original. begin iterator.
  • constexpr const_iterator begin () const noexcept β€” no description in the original. constexpr const begin.
  • const_iterator begin () const noexcept β€” no description in the original. non-constexpr const begin.
  • constexpr iterator begin () noexcept β€” no description in the original. constexpr begin.
  • constexpr const _CharT * c_str () const noexcept β€” return const pointer to null-terminated contents. c_str core.
  • const _CharT * c_str () const noexcept β€” return const pointer to null-terminated contents. non-constexpr.
  • constexpr size_type capacity () const noexcept β€” no description in the original. capacity tea.
  • size_type capacity () const noexcept β€” no description in the original. non-constexpr capacity.
  • constexpr const_iterator cbegin () const noexcept β€” no description in the original. cbegin.
  • const_iterator cbegin () const noexcept β€” no description in the original. non-constexpr cbegin.
  • constexpr const_iterator cend () const noexcept β€” no description in the original. cend.
  • const_iterator cend () const noexcept β€” no description in the original. non-constexpr cend.
  • constexpr void clear () noexcept β€” no description in the original. clear it.
  • void clear () noexcept β€” no description in the original. non-constexpr clear.
  • constexpr int compare (const _CharT *__s) const noexcept β€” compare to a C string. compare szn.
  • int compare (const _CharT *__s) const noexcept β€” compare to a C string. non-constexpr.
  • constexpr int compare (const basic_string &__str) const β€” compare to a string. string compare.
  • int compare (const basic_string &__str) const β€” compare to a string. non-constexpr.
  • constexpr int compare (size_type __pos, size_type __n, const basic_string &__str) const β€” compare substring to a string. substring compare.
  • int compare (size_type __pos, size_type __n, const basic_string &__str) const β€” compare substring to a string. non-constexpr.
  • constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s) const β€” compare substring to a C string. substring vs C string.
  • int compare (size_type __pos, size_type __n1, const _CharT *__s) const β€” compare substring to a C string. non-constexpr.
  • constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const β€” compare substring against a character array. substring vs char array.
  • int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const β€” compare substring against a character array. non-constexpr.
  • constexpr int compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) const β€” compare substring to a substring. substring vs substring, the finale.
  • int compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) const β€” compare substring to a substring. non-constexpr twin.

okay bestie we're STILL in the SYNOPSIS and she is long β€” grab a snack πŸ“ this is the part where the overloads start showing up in pairs like twins who refuse to be separated πŸ’…

  • constexpr bool contains (_CharT __x) const noexcept β€” does she contain this one lil character? constexpr era, so she can answer at compile time ✨
  • bool contains (_CharT __x) const noexcept β€” same question, non-constexpr twin 🌸
  • constexpr bool contains (basic_string_view< _CharT, _Traits > __x) const noexcept β€” does she contain this whole basic_string_view? constexpr one πŸ’«
  • bool contains (basic_string_view< _CharT, _Traits > __x) const noexcept β€” the other twin, no constexpr πŸŽ€
  • constexpr bool contains (const _CharT *__x) const noexcept β€” does she contain this C-string? constexpr flavor πŸ”₯
  • bool contains (const _CharT *__x) const noexcept β€” the plain twin, same question πŸ¦‹
  • constexpr size_type copy (_CharT *__s, size_type __n, size_type __pos=0) const β€” copy substring into C string 🫢 she takes __n characters starting from __pos=0 and drops them into your C string
  • size_type copy (_CharT *__s, size_type __n, size_type __pos=0) const β€” same mission, non-constexpr edition πŸ’–
  • constexpr const_reverse_iterator crbegin () const noexcept β€” the reverse-beginning, const flavor, constexpr flavor, she's giving everything πŸ‘‘
  • const_reverse_iterator crbegin () const noexcept β€” her non-constexpr twin 🌈
  • constexpr const_reverse_iterator crend () const noexcept β€” reverse-end, const + constexpr ⭐
  • const_reverse_iterator crend () const noexcept β€” the non-constexpr twin, no blurb needed, she's self-explanatory πŸ’…
  • constexpr const _CharT * data () const noexcept β€” return const pointer to contents β€” peek, don't touch πŸ”
  • const _CharT * data () const noexcept β€” same const-pointer energy, non-constexpr 🌸
  • constexpr _CharT * data () noexcept β€” return non-const pointer to contents β€” okay now you CAN touch, behave yourself 😭
  • _CharT * data () noexcept(false) β€” non-const pointer to contents, and yes bestie that noexcept(false) is right there in the source, do not come for me πŸ™ˆ
  • constexpr bool empty () const noexcept β€” is she empty? constexpr said it first ✨
  • bool empty () const noexcept β€” is she empty? other twin πŸŽ€
  • iterator end () β€” end iterator, plain and unbothered πŸ¦‹
  • constexpr const_iterator end () const noexcept β€” const end iterator, constexpr edition πŸ’«
  • const_iterator end () const noexcept β€” const end iterator, no constexpr πŸ’œ
  • constexpr iterator end () noexcept β€” non-const end iterator that IS constexpr πŸ”₯
  • constexpr bool ends_with (_CharT __x) const noexcept β€” does she end with this character? constexpr πŸ’…
  • bool ends_with (_CharT __x) const noexcept β€” same Q, non-constexpr twin 🌸
  • constexpr bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” does she end with this basic_string_view? constexpr ✨
  • bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” her twin πŸŽ€
  • constexpr bool ends_with (const _CharT *__x) const noexcept β€” does she end with this C-string? constexpr πŸ”₯
  • bool ends_with (const _CharT *__x) const noexcept β€” her twin, no constexpr πŸ¦‹
  • constexpr iterator erase (__const_iterator __first, __const_iterator __last) β€” remove a range of characters β€” full yeet, __first to __last πŸ’€
  • constexpr iterator erase (__const_iterator __position) β€” remove one character β€” surgical yeet, one single victim πŸ™ˆ
  • iterator erase (iterator __first, iterator __last) β€” remove a range of characters, non-constexpr twin, and note she takes iterator here not __const_iterator πŸ‘€
  • iterator erase (iterator __position) β€” remove one character, twin energy πŸŽ€
  • constexpr basic_string & erase (size_type __pos=0, size_type __n=npos) β€” remove characters β€” defaults are __pos=0 and __n=npos, so she'll clear the whole thing if you don't say otherwise 😭
  • basic_string & erase (size_type __pos=0, size_type __n=npos) β€” same defaults, non-constexpr twin 🌸
  • constexpr size_type find (_CharT __c, size_type __pos=0) const noexcept β€” find position of a character β€” where is __c hiding, starting at __pos=0 πŸ”
  • size_type find (_CharT __c, size_type __pos=0) const noexcept β€” her twin πŸŽ€
  • constexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find position of a C substring, you supply both __pos and __n ✨
  • size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” twin πŸ¦‹
  • constexpr size_type find (const _CharT *__s, size_type __pos=0) const noexcept β€” find position of a C string, __pos=0 default πŸ’«
  • size_type find (const _CharT *__s, size_type __pos=0) const noexcept β€” twin πŸ’œ
  • constexpr size_type find (const basic_string &__str, size_type __pos=0) const noexcept β€” find position of a string 🌸
  • size_type find (const basic_string &__str, size_type __pos=0) const noexcept β€” twin πŸŽ€
  • constexpr size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexcept β€” find position of a different character β€” the first one that is NOT __c πŸ’…
  • size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexcept β€” twin 🌈
  • constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find position of a character not in C substring ✨
  • size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” twin πŸ¦‹
  • constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexcept β€” find position of a character not in C string, __pos=0 default πŸŽ€
  • size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexcept β€” twin πŸ’œ
  • constexpr size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexcept β€” find position of a character not in string 🌸
  • size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexcept β€” twin ⭐
  • constexpr size_type find_first_of (_CharT __c, size_type __pos=0) const noexcept β€” find position of a character πŸ”
  • size_type find_first_of (_CharT __c, size_type __pos=0) const noexcept β€” twin πŸŽ€
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find position of a character of C substring ✨
  • size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” twin πŸ¦‹
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept β€” find position of a character of C string πŸ’«
  • size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept β€” twin πŸ’œ
  • constexpr size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexcept β€” find position of a character of string 🌸
  • size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexcept β€” twin πŸŽ€
  • constexpr size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexcept β€” find last position of a different character β€” and heads up, the default here is __pos=npos, not 0 πŸ‘€
  • size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexcept β€” twin 🌈
  • constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find last position of a character not in C substring ✨
  • size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” twin πŸ¦‹
  • constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const noexcept β€” find last position of a character not in C string, __pos=npos default πŸŽ€
  • size_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const noexcept β€” twin πŸ’œ
  • constexpr size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexcept β€” find last position of a character not in string 🌸
  • size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexcept β€” twin ⭐
  • constexpr size_type find_last_of (_CharT __c, size_type __pos=npos) const noexcept β€” find last position of a character, default __pos=npos πŸ”
  • size_type find_last_of (_CharT __c, size_type __pos=npos) const noexcept β€” twin πŸŽ€
  • constexpr size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find last position of a character of C substring ✨
  • size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” twin πŸ¦‹
  • constexpr size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexcept β€” find last position of a character of C string πŸ’«
  • size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexcept β€” twin πŸ’œ
  • constexpr size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexcept β€” find last position of a character of string 🌸
  • size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexcept β€” twin πŸŽ€
  • reference front () β€” the front, plain edition, no blurb in the source, she just is πŸ’…
  • constexpr const_reference front () const noexcept β€” const front, constexpr ✨
  • const_reference front () const noexcept β€” const front, no constexpr 🌸
  • constexpr reference front () noexcept β€” non-const front that's constexpr πŸ”₯
  • constexpr allocator_type get_allocator () const noexcept β€” return copy of allocator used to construct this string β€” she hands you a copy, not the real one 🫢
  • allocator_type get_allocator () const noexcept β€” same copy-of-the-allocator deal, non-constexpr twin πŸŽ€
  • constexpr iterator insert (__const_iterator __p, _CharT __c) β€” insert one character β€” one single character, placed at __p πŸ’«
  • template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr iterator insert (const_iterator __p, _InputIterator __beg, _InputIterator __end) β€” insert a range of characters, and look at that _RequireInputIter constraint, she's picky and she's right πŸŽ€
  • constexpr iterator insert (const_iterator __p, initializer_list< _CharT > __l) β€” insert an initializer_list of characters 🌸
  • constexpr iterator insert (const_iterator __p, size_type __n, _CharT __c) β€” insert multiple characters, __n copies of __c ✨
  • iterator insert (iterator __p, _CharT __c) β€” insert one character, non-constexpr twin, note it's iterator __p not const_iterator πŸ‘€
  • template<class _InputIterator> void insert (iterator __p, _InputIterator __beg, _InputIterator __end) β€” insert a range of characters, twin β€” and no _RequireInputIter on this one, just plain class _InputIterator πŸ¦‹
  • void insert (iterator __p, initializer_list< _CharT > __l) β€” insert an initializer_list of characters, twin πŸ’œ
  • void insert (iterator __p, size_type __n, _CharT __c) β€” insert multiple characters, twin πŸŽ€
  • constexpr basic_string & insert (size_type __pos, const _CharT *__s) β€” insert a C string at __pos 🌸
  • basic_string & insert (size_type __pos, const _CharT *__s) β€” twin πŸ¦‹
  • constexpr basic_string & insert (size_type __pos, const _CharT *__s, size_type __n) β€” insert a C substring πŸ’«
  • basic_string & insert (size_type __pos, const _CharT *__s, size_type __n) β€” twin πŸ’œ
  • constexpr basic_string & insert (size_type __pos, size_type __n, _CharT __c) β€” insert multiple characters ✨
  • basic_string & insert (size_type __pos, size_type __n, _CharT __c) β€” twin πŸŽ€
  • constexpr basic_string & insert (size_type __pos1, const basic_string &__str) β€” insert value of a string, and yes the parameter is __pos1 here 🌸
  • basic_string & insert (size_type __pos1, const basic_string &__str) β€” twin πŸ¦‹
  • constexpr basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos) β€” insert a substring, four params deep and __n=npos by default πŸ’«
  • basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos) β€” twin πŸ’œ
  • constexpr size_type length () const noexcept β€” returns the number of characters in the string, not including any null-termination β€” the null-terminator does NOT get counted, bestie, she's not that kind of girl 😭
  • size_type length () const noexcept β€” same count, non-constexpr twin πŸŽ€
  • constexpr size_type max_size () const noexcept β€” returns the size() of the largest possible string β€” the absolute biggest she could ever be πŸ‘‘

and we are STILL not done, do not close the terminal, more overloads incoming πŸ˜­πŸ’–

  • size_type max_size () const noexcept β€” tells you the size() of the largest possible string. like, the absolute theoretical ceiling of string, bestie. you will never hit it. it's giving "max capacity, no cap" πŸ’–
  • constexpr basic_string & operator+= (_CharT __c) β€” append a character ✨
  • basic_string & operator+= (_CharT __c) β€” append a character (same thing, the runtime twin)
  • constexpr basic_string & operator+= (const _CharT *__s) β€” append a C string 🌸
  • basic_string & operator+= (const _CharT *__s) β€” append a C string
  • constexpr basic_string & operator+= (const basic_string &__str) β€” append a whole string onto this string 🫢
  • basic_string & operator+= (const basic_string &__str) β€” append a string to this string
  • constexpr basic_string & operator+= (initializer_list< _CharT > __l) β€” append an initializer_list of characters πŸ’…
  • basic_string & operator+= (initializer_list< _CharT > __l) β€” append an initializer_list of characters
  • constexpr basic_string & operator= (_CharT __c) β€” set the value to a string of length 1 🌷
  • basic_string & operator= (_CharT __c) β€” set value to string of length 1
  • basic_string & operator= (basic_string &&__str) noexcept(/*conditional */) β€” move-assign the value of str into this string 🚚
  • constexpr basic_string & operator= (basic_string &&__str) noexcept(_Alloc_traits::_S_nothrow_move()) β€” move assign the value of str to this string
  • constexpr basic_string & operator= (const _CharT *__s) β€” copy the contents of s into this string ✨
  • basic_string & operator= (const _CharT *__s) β€” copy contents of s into this string
  • constexpr basic_string & operator= (const basic_string &__str) β€” assign the value of str to this string πŸ’–
  • basic_string & operator= (const basic_string &__str) β€” assign the value of str to this string
  • constexpr basic_string & operator= (initializer_list< _CharT > __l) β€” set the value to a string constructed from an initializer list πŸŽ€
  • basic_string & operator= (initializer_list< _CharT > __l) β€” set value to string constructed from initializer list
  • basic_string & operator= (nullptr_t)=delete β€” DELETED. not allowed, don't even try it, it's literally been erased from existence πŸ’€
  • basic_string & operator= (nullptr_t)=delete β€” deleted (yes, again, that's the point)
  • constexpr reference operator[] (size_type __pos) β€” subscript access to the data chillin' inside the string πŸ‘‘
  • reference operator[] (size_type __pos) β€” subscript access to the data contained in the string
  • constexpr const_reference operator[] (size_type __pos) const noexcept β€” the const version of that subscript access, same vibe πŸ¦‹
  • const_reference operator[] (size_type __pos) const noexcept β€” subscript access to the data contained in the string
  • void pop_back () β€” remove the last character. bye bestie πŸ‘‹
  • constexpr void pop_back () noexcept β€” remove the last character
  • constexpr void push_back (_CharT __c) β€” append a single character πŸ’œ
  • void push_back (_CharT __c) β€” append a single character
  • reverse_iterator rbegin () β€” (no blurb given for this one, it just exists and does its thing) 🌈
  • constexpr const_reverse_iterator rbegin () const noexcept β€” (no blurb, but she's here)
  • const_reverse_iterator rbegin () const noexcept β€” (still no blurb, iconic silence)
  • constexpr reverse_iterator rbegin () noexcept β€” (no description supplied)
  • reverse_iterator rend () β€” (no blurb in the original, just vibes) ✨
  • constexpr const_reverse_iterator rend () const noexcept β€” (no blurb)
  • const_reverse_iterator rend () const noexcept β€” (no blurb)
  • constexpr reverse_iterator rend () noexcept β€” (no description given)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, _CharT *__k1, _CharT *__k2) β€” (no blurb for this overload, it's just there)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__k1, const _CharT *__k2) β€” (no blurb either)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s) β€” replace a range of characters with a C string 🌸
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s, size_type __n) β€” replace a range of characters with a C substring ✨
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const basic_string &__str) β€” replace a range of characters with a string πŸ’–
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const_iterator __k1, const_iterator __k2) β€” (no blurb)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, iterator __k1, iterator __k2) β€” (no blurb)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, size_type __n, _CharT __c) β€” replace a range of characters with multiple characters πŸŽ€
  • template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, _InputIterator __k1, _InputIterator __k2) β€” replace a range of characters with a range πŸ¦‹
  • constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, initializer_list< _CharT > __l) β€” replace a range of characters with an initializer_list πŸ’…
  • basic_string & replace (iterator __i1, iterator __i2, _CharT *__k1, _CharT *__k2) β€” (no blurb)
  • template<class _InputIterator> basic_string & replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2) β€” replace a range of characters with a range ✨
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__k1, const _CharT *__k2) β€” (no blurb)
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s) β€” replace a range of characters with a C string 🌸
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s, size_type __n) β€” replace a range of characters with a C substring
  • basic_string & replace (iterator __i1, iterator __i2, const basic_string &__str) β€” replace a range of characters with a string πŸ’œ
  • basic_string & replace (iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2) β€” (no blurb)
  • basic_string & replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l) β€” replace a range of characters with an initializer_list πŸŽ€
  • basic_string & replace (iterator __i1, iterator __i2, iterator __k1, iterator __k2) β€” (no blurb)
  • basic_string & replace (iterator __i1, iterator __i2, size_type __n, _CharT __c) β€” replace a range of characters with multiple characters πŸ”₯
  • constexpr basic_string & replace (size_type __pos, size_type __n, const basic_string &__str) β€” replace characters with a value from another string 🫢
  • basic_string & replace (size_type __pos, size_type __n, const basic_string &__str) β€” replace characters with value from another string
  • constexpr basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s) β€” replace characters with the value of a C string ✨
  • basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s) β€” replace characters with value of a C string
  • constexpr basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) β€” replace characters with the value of a C substring πŸ’–
  • basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) β€” replace characters with value of a C substring
  • constexpr basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c) β€” replace characters with multiple characters 🌷
  • basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c) β€” replace characters with multiple characters
  • constexpr basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) β€” replace characters with a value from another string πŸ‘‘
  • basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) β€” replace characters with value from another string
  • constexpr void reserve () β€” (no blurb for this one)
  • void reserve () β€” equivalent to shrink_to_fit() 🧚
  • constexpr void reserve (size_type __res_arg) β€” try to preallocate enough memory for the specified number of characters πŸ’…
  • void reserve (size_type __res_arg) β€” attempt to preallocate enough memory for specified number of characters
  • constexpr void resize (size_type __n) β€” resizes the string to the specified number of characters πŸ¦‹
  • void resize (size_type __n) β€” resizes the string to the specified number of characters
  • constexpr void resize (size_type __n, _CharT __c) β€” resizes the string to the specified number of characters ✨
  • void resize (size_type __n, _CharT __c) β€” resizes the string to the specified number of characters
  • constexpr size_type rfind (_CharT __c, size_type __pos=npos) const noexcept β€” find the last position of a character (reverse search, main character energy) πŸ”
  • size_type rfind (_CharT __c, size_type __pos=npos) const noexcept β€” find last position of a character
  • constexpr size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find the last position of a C substring 🌸
  • size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find last position of a C substring
  • constexpr size_type rfind (const _CharT *__s, size_type __pos=npos) const β€” find the last position of a C string πŸ’œ
  • size_type rfind (const _CharT *__s, size_type __pos=npos) const noexcept β€” find last position of a C string
  • constexpr size_type rfind (const basic_string &__str, size_type __pos=npos) const noexcept β€” find the last position of a string πŸŽ€
  • size_type rfind (const basic_string &__str, size_type __pos=npos) const noexcept β€” find last position of a string
  • constexpr void shrink_to_fit () noexcept β€” a non-binding request to shrink capacity() down to size() β€” keyword non-binding, so it can absolutely ignore you πŸ™ˆ
  • void shrink_to_fit () noexcept β€” a non-binding request to reduce capacity() to size()
  • constexpr size_type size () const noexcept β€” returns the number of characters in the string, not counting any null-termination πŸ’–
  • size_type size () const noexcept β€” returns the number of characters in the string, not including any null-termination
  • constexpr bool starts_with (_CharT __x) const noexcept β€” (no blurb given)
  • bool starts_with (_CharT __x) const noexcept β€” (no blurb)
  • constexpr bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” (no blurb)
  • bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” (no blurb)
  • constexpr bool starts_with (const _CharT *__x) const noexcept β€” (no blurb)
  • bool starts_with (const _CharT *__x) const noexcept β€” (no blurb)
  • constexpr basic_string substr (size_type __pos, size_type __n) && β€” (no blurb for this rvalue overload)
  • constexpr basic_string substr (size_type __pos=0) && β€” (no blurb)
  • constexpr basic_string substr (size_type __pos=0, size_type __n=npos) const β€” get a substring βœ‚οΈ
  • basic_string substr (size_type __pos=0, size_type __n=npos) const β€” get a substring
  • constexpr basic_string_view< _CharT, _Traits > subview (size_type __pos=0, size_type __n=npos) const β€” get a subview πŸ‘€
  • constexpr basic_string_view< _CharT, _Traits > subview (size_type __pos=0, size_type __n=npos) const β€” get a subview (yes, listed twice, that's the docs' business not mine)
  • constexpr void swap (basic_string &__s) noexcept β€” swap contents with another string πŸ”„βœ¨
  • void swap (basic_string &__s) noexcept(/*conditional */) β€” trades contents with another string. Bestie swap, no cap. ✨

🌸 Static Public Attributes 🌸

  • static const size_type npos β€” the iconic "nope, that didn't work" value. All the member functions that fail come back holding this. It's giving "not found, babe." πŸ’…

πŸŽ€ Protected Types πŸŽ€

  • typedef const_iterator __const_iterator
  • typedef iterator __const_iterator

(yes, it literally says that twice, and no, we are not editing the source, we respect the ancestors πŸ™ˆ)

🫢 Friends 🫢

  • template<typename, typename, typename> class basic_stringbuf

πŸ‘‘ Detailed Description πŸ‘‘

template<typename _CharT, typename _Traits, typename _Alloc>
    class std::basic_string< _CharT, _Traits, _Alloc >

Managing sequences of characters and character-like objects. That's the whole job. That's the assignment. ✨

Since: C++98 (an elder, a legend, a founding mother 🫢)

Template Parameters

  • _CharT β€” type of character
  • _Traits β€” traits for character type, defaults to char_traits<_CharT>
  • _Alloc β€” allocator type, defaults to allocator<_CharT>

It meets the requirements of a container, a reversible container, and a sequence. And of the optional sequence requirements? Only push_back, at, and array access are supported. That's it. That's the list. Don't come for her about the others. πŸ’€

Since: C++98

Template Parameters

  • _CharT β€” type of character
  • _Traits β€” traits for character type, defaults to char_traits<_CharT>
  • _Alloc β€” allocator type, defaults to allocator<_CharT>

It meets the requirements of a container, a reversible container, and a sequence. Of the optional sequence requirements, only push_back, at, and array access are supported. (Yep, the manpage says this whole thing twice. We are simply built different. We repeat ourselves. Periodt. 😌)

Todo β€” Needs documentation! See http://gcc.gnu.org/onlinedocs/libstdc++/manual/documentation_style.html

Documentation? What's that? Nathan Myers ncm@cantrip.org. β€” an absolute icon, honestly, the confidence, the audacity, the legacy. 🌈


πŸ¦‹ A string looks like this πŸ¦‹

                                     [_Rep]
                                     _M_length
[basic_string<char_type>]            _M_capacity
_M_dataplus                          _M_refcount
_M_p ---------------->               unnamed array of char_type

Okay so let's decode the vibe check here. πŸ’…

Where the _M_p points to the first character in the string, and you cast it to a pointer-to-_Rep and subtract 1 to get a pointer to the header. Yes bestie, we're doing pointer arithmetic before breakfast. 🧚

This approach has the enormous advantage that a string object requires only one allocation. All the ugliness is confined within a single pair of inline functions, which each compile to a single add instruction: _Rep::_M_data(), and string::_M_rep(); and the allocation function which gets a block of raw bytes and with room enough and constructs a _Rep object at the front. She's efficient. She's lowkey elegant. She ate. πŸ”₯

The reason you want _M_data pointing to the character array and not the _Rep is so that the debugger can see the string contents. (Probably we should add a non-inline member to get the _Rep for the debugger to use, so users can check the actual string length.) Not me exposing the debugger's whole situation like this 😭

Note that the _Rep object is a POD so that you can have a static empty string _Rep object already constructed before static constructors have run. The reference-count encoding is chosen so that a 0 indicates one reference, so you never try to destroy the empty-string _Rep object. It's giving "the empty string cannot be killed." Iconic. Untouchable. πŸ‘‘

All but the last paragraph is considered pretty conventional for a Copy-On-Write C++ string implementation. β€” the last paragraph being the special one, the main character, the exception to the rule. πŸŽ€

πŸ’– Constructor & Destructor Documentation πŸ’–

okay bestie, this is the part where the string gets born 🍼✨ and, spoiler, it also gets yeeted into the void at the end. Let's go one by one, no skips, no cap.

Also heads up: the page runs the whole set twice β€” once with the [constexpr] glow-up and once without. Both are here, fr fr, nothing dropped. πŸ’…


🌸 the no-arg glow-up

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string () [inline], [constexpr], [noexcept]

Default constructor creates an empty string. an empty queen, a blank canvas, a whole mood πŸŽ€

Referenced by std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::substr(), and swap().

not me listing assign() twice β€” the manpage said it twice, so bestie, so do I. we do NOT drop duplicates. periodt.

🧚 the "bring your own allocator" starter pack

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _Alloc & __a) [inline], [explicit], [constexpr], [noexcept]

Construct an empty string using allocator a.

note the [explicit] β€” it's giving "no sneaky implicit conversions, we're classy here" πŸ’…


πŸ¦‹ the copycat (iconic behaviour honestly)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]

Construct string with copy of value of __str.

Parameters

  • __str β€” Source string.

πŸŽ€ copy but make it a substring (pos only)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, const _Alloc & __a = _Alloc()) [inline], [constexpr]

Construct string as copy of a substring.

Parameters

  • __str β€” Source string.
  • __pos β€” Index of first character to copy from.
  • __a β€” Allocator to use.

🌈 copy but make it a substring (pos + length)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n) [inline], [constexpr]

Construct string as copy of a substring.

Parameters

  • __str β€” Source string.
  • __pos β€” Index of first character to copy from.
  • __n β€” Number of characters to copy.

πŸ’œ the FULL send substring: pos + length + allocator

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n, const _Alloc & __a) [inline], [constexpr]

Construct string as copy of a substring.

Parameters

  • __str β€” Source string.
  • __pos β€” Index of first character to copy from.
  • __n β€” Number of characters to copy.
  • __a β€” Allocator to use.

πŸ“ char array β†’ string (length-based, '\0' is NOT special)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, size_type __n, const _Alloc & __a = _Alloc()) [inline], [constexpr]

Construct string initialized by a character array.

Parameters

  • __s β€” Source character array.
  • __n β€” Number of characters to copy.
  • __a β€” Allocator to use (default is default allocator).
NB: __s must have at least __n characters, '\0' has no special meaning. bestie this is the important bit β€” it does NOT stop at the null terminator, it takes what you tell it to take. don't get caught slippin' πŸ’€

✨ C string β†’ string (the '\0'-aware one)

template<typename _CharT, typename _Traits, typename _Alloc>
template<typename = _RequireAllocator<_Alloc>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, const _Alloc & __a = _Alloc()) [inline], [constexpr]

Construct string as copy of a C string.

Parameters

  • __s β€” Source C string.
  • __a β€” Allocator to use (default is default allocator).

🫢 fill 'er up: n copies of one character

template<typename _CharT, typename _Traits, typename _Alloc>
template<typename = _RequireAllocator<_Alloc>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (size_type __n, _CharT __c, const _Alloc & __a = _Alloc()) [inline], [constexpr]

Construct string as multiple characters.

Parameters

  • __n β€” Number of characters.
  • __c β€” Character to use.
  • __a β€” Allocator to use (default is default allocator).

πŸ”₯ the MOVE constructor (steal the vibe, leave them guessing)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [constexpr], [noexcept]

Move construct string.

Parameters

  • __str β€” Source string.

The newly-created string contains the exact contents of __str. __str is a valid, but unspecified string.

translation: new string ate everything 🍽️, old string is still alive but it's giving "idk what I am anymore" β€” valid but unspecified, okay?? don't touch it and expect specific contents.

🌟 initializer list, but make it a string

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (initializer_list< _CharT > __l, const _Alloc & __a = _Alloc()) [inline], [constexpr]

Construct string from an initializer list.

Parameters

  • __l β€” std::initializer_list of characters.
  • __a β€” Allocator to use (default is default allocator).

🧚 the iterator range one (beg to end, no cap)

template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc & __a = _Alloc()) [inline], [constexpr]

Construct string as copy of a range.

Parameters

  • __beg β€” Start of range.
  • __end β€” End of range.
  • __a β€” Allocator to use (default is default allocator).

πŸ’€ and now… the DESTRUCTOR (rip bozo)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::~basic_string () [inline], [constexpr]

Destroy the string instance.

she served her purpose, she's done, she's free now πŸ•ŠοΈ


🌸 okay now the SAME constructors again, but the non-constexpr edition 🌸

same roster, different sparkle ✨

πŸŽ€ default constructor (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string () [inline], [noexcept]

Default constructor creates an empty string.


🧚 allocator constructor (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _Alloc & __a) [inline], [explicit]

Construct an empty string using allocator a.


πŸ¦‹ copy constructor (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline]

Construct string with copy of value of str.

Parameters

  • __str β€” Source string.

🌈 substring, pos-only (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, const _Alloc & __a = _Alloc())

Construct string as copy of a substring.

Parameters

  • __str β€” Source string.
  • __pos β€” Index of first character to copy from.
  • __a β€” Allocator to use.

πŸ“ substring, pos + n (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n)

Construct string as copy of a substring.

Parameters

  • __str β€” Source string.
  • __pos β€” Index of first character to copy from.
  • __n β€” Number of characters to copy.

πŸ’œ substring, pos + n + allocator (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n, const _Alloc & __a)

Construct string as copy of a substring.

Parameters

  • __str β€” Source string.
  • __pos β€” Index of first character to copy from.
  • __n β€” Number of characters to copy.
  • __a β€” Allocator to use.

🫢 char array + length (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, size_type __n, const _Alloc & __a = _Alloc()) [inline]

Construct string initialized by a character array.

Parameters

  • __s β€” Source character array.
  • __n β€” Number of characters to copy.
  • __a β€” Allocator to use (default is default allocator).
NB: __s must have at least __n characters, '\0' has no special meaning. still true, still important πŸ’…

✨ C string (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
template<typename = _RequireAllocator<_Alloc>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, const _Alloc & __a = _Alloc()) [inline]

Construct string as copy of a C string.

Parameters

  • __s β€” Source C string.
  • __a β€” Allocator to use (default is default allocator).

🌟 n copies of a character (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (size_type __n, _CharT __c, const _Alloc & __a = _Alloc()) [inline]

Construct string as multiple characters.

Parameters

  • __n β€” Number of characters.
  • __c β€” Character to use.
  • __a β€” Allocator to use (default is default allocator).

πŸ”₯ move constructor (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [noexcept]

Move construct string.

Parameters

  • __str β€” Source string.

The newly-created string contains the exact contents of __str. __str is a valid, but unspecified string.


🌈 initializer list (round two)

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (initializer_list< _CharT > __l, const _Alloc & __a = _Alloc()) [inline]

Construct string from an initializer list.

Parameters

  • __l β€” std::initializer_list of characters.
  • __a β€” Allocator to use (default is default allocator).

🧚 iterator range (round two, class template style)

template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc & __a = _Alloc()) [inline]

Construct string as copy of a range.

Parameters

  • __beg β€” Start of range.
  • __end β€” End of range.
  • __a β€” Allocator to use (default is default allocator).

πŸ’€ destructor (round two, this time it's [noexcept])

template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::~basic_string () [inline], [noexcept]

Destroy the string instance.


πŸ‘‘ Member Function Documentation πŸ‘‘

and now we're in the member functions, bestie, strap in πŸ’…


🧚 __resize_and_overwrite β€” the double-underscore special

template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _Operation>
void std::basic_string< _CharT, _Traits, _Alloc >::__resize_and_overwrite (size_type __n, _Operation __op) [constexpr]

Non-standard version of resize_and_overwrite for C++11 and above.


🧚 __resize_and_overwrite β€” again, but non-constexpr

template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _Operation>
void std::basic_string< _CharT, _Traits, _Alloc >::__resize_and_overwrite (size_type __n, _Operation __op)

Non-standard version of resize_and_overwrite for C++11 and above.


πŸ¦‹ append β€” range edition (with the constexpr glow)

template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (_InputIterator __first, _InputIterator __last) [inline], [constexpr]

Append a range of characters.

Parameters

  • __first β€” Iterator referencing the first character to append.
  • __last β€” Iterator marking the end of the range.

Returns

  • Reference to this string.

Appends characters in the range [__first,__last) to this string.


πŸŽ€ append β€” range edition (no constexpr, still iconic)

template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (_InputIterator __first, _InputIterator __last) [inline]

Append a range of characters.

…and that's where this part wraps, bestie β€” more member functions are waiting in the next chunk, don't go anywhere 🫢

okay so that iterator-range append we just opened up β€” here's the rest of its paperwork, bestie 🫢

  • __first β€” iterator referencing the first character to append ✨
  • __last β€” iterator marking the end of the range πŸŽ€

Returns: a reference to this string, always, so you can chain these forever πŸ’…

What it do: appends the characters in the range [__first,__last) to this string. that's the whole job. no cap 🌸


πŸ”₯ append β€” append a C string ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s) [inline], [constexpr]

Append a C string. yes, literally just yeet a whole C string onto the end πŸ“

  • __s β€” the C string to append

Returns: reference to this string πŸ’–

πŸ”₯ append β€” append a C string ([inline])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s) [inline]

the non-constexpr twin of the one above, same energy, same everything:

  • __s β€” the C string to append

Returns: reference to this string πŸ’–

πŸ¦‹ append β€” append a C substring ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s, size_type __n) [inline], [constexpr]

Append a C substring β€” so, only part of the C string, because sometimes you don't want the whole thing πŸ‘‘

  • __s β€” the C string to append
  • __n β€” the number of characters to append

Returns: reference to this string πŸ’œ

πŸ¦‹ append β€” append a C substring (no [inline]/[constexpr] tag)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s, size_type __n)

Append a C substring. same deal as the one right above, just the other variant:

  • __s β€” the C string to append
  • __n β€” the number of characters to append

Returns: reference to this string πŸ’œ

πŸ‘‘ append β€” append a string ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]

Append a string to this string. string-on-string action, iconic 🌈

  • __str β€” the string to append

Returns: reference to this string πŸ’–

Referenced by:

  • std::basic_string< _CharT >::append()
  • std::basic_string< _CharT >::append()
  • std::basic_string< _CharT >::append()
  • std::basic_string< _CharT >::append()
  • std::__cxx11::collate< _CharT >::do_transform()
  • std::basic_string< _CharT >::operator+=()
  • std::basic_string< _CharT >::operator+=()
  • std::basic_string< _CharT >::operator+=()
  • std::operator>>()
  • resize()

πŸ‘‘ append β€” append a string (other variant)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str)

Append a string to this string. the sibling of the one above, same facts:

  • __str β€” the string to append

Returns: reference to this string πŸ’–

πŸŽ€ append β€” append a substring ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n = npos) [inline], [constexpr]

Append a substring β€” slice of a string, bestie, we're picking a starting point AND a length πŸ”ͺ✨

  • __str β€” the string to append
  • __pos β€” index of the first character of str to append
  • __n β€” the number of characters to append

Returns: reference to this string πŸ’–

Exceptions: std::out_of_range if __pos is not a valid index. so like, don't be messy with your indices, fr fr 😭

This function appends __n characters from __str starting at __pos to this string. And if __n is larger than the number of available characters in __str, the remainder of __str is appended. it just takes what it can get, main character energy πŸ‘‘

πŸŽ€ append β€” append a substring (other variant)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n = npos)

Append a substring. the matching non-constexpr/non-[inline] version:

  • __str β€” the string to append
  • __pos β€” index of the first character of str to append
  • __n β€” the number of characters to append

Returns: reference to this string πŸ’–

Exceptions: std::out_of_range if __pos is not a valid index. still true, still will ruin your day πŸ™ˆ

This function appends __n characters from __str starting at __pos to this string. If __n is larger than the number of available characters in __str, the remainder of __str is appended. same as above, exact same rules 🌸

🧚 append β€” append an initializer_list ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (initializer_list< _CharT > __l) [inline], [constexpr]

Append an initializer_list of characters. curly-brace girlies, this one's for you πŸŽ€

  • __l β€” the initializer_list of characters to append

Returns: reference to this string πŸ’œ

🧚 append β€” append an initializer_list ([inline])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (initializer_list< _CharT > __l) [inline]

Append an initializer_list of characters. the twin, same vibes:

  • __l β€” the initializer_list of characters to append

Returns: reference to this string πŸ’œ

πŸ’… append β€” append multiple characters ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (size_type __n, _CharT __c) [inline], [constexpr]

Append multiple characters β€” one character, repeated. the remix 🎡

  • __n β€” the number of characters to append
  • __c β€” the character to use

Returns: reference to this string πŸ’–

Appends __n copies of __c to this string. yes, __n copies. count them. ⭐

πŸ’… append β€” append multiple characters (other variant)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (size_type __n, _CharT __c)

Append multiple characters. the non-constexpr twin:

  • __n β€” the number of characters to append
  • __c β€” the character to use

Returns: reference to this string πŸ’–

Appends __n copies of __c to this string. still __n copies. still slaying 🫢


🌟 and now… assign 🌟

new function drop!! assign doesn't add to your string β€” it replaces the whole value. it's giving makeover episode πŸ’„

πŸ¦‹ assign β€” set value to a range of characters ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (_InputIterator __first, _InputIterator __last) [inline], [constexpr]

Set value to a range of characters πŸ”

  • __first β€” iterator referencing the first character to append
  • __last β€” iterator marking the end of the range

Returns: reference to this string πŸ’–

Sets value of string to characters in the range [__first,__last). so whatever was in there before? gone. replaced. glow-up complete ✨

πŸ¦‹ assign β€” set value to a range of characters ([inline])

template<typename _CharT, typename _Traits, typename _Alloc> template<class _InputIterator> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (_InputIterator __first, _InputIterator __last) [inline]

Set value to a range of characters. the sibling overload, note it has no std::_RequireInputIter constraint in its template list πŸ‘€

  • __first β€” iterator referencing the first character to append
  • __last β€” iterator marking the end of the range

Returns: reference to this string πŸ’–

Sets value of string to characters in the range [__first,__last). same rules, same range, same energy 🌸

πŸ‘‘ assign β€” set value to contents of another string ([inline], [constexpr], [noexcept])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [constexpr], [noexcept]

Set value to contents of another string β€” and it's an rvalue ref, so we're moving, bestie πŸššπŸ’¨

  • __str β€” source string to use

Returns: reference to this string πŸ’–

This function sets this string to the exact contents of __str. And listen: __str is a valid, but unspecified string afterward. so don't go reading it and expecting your data back, it's been through something 😭

πŸ‘‘ assign β€” set value to contents of another string ([inline], [noexcept])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [noexcept]

Set value to contents of another string. the other variant, no [constexpr] tag on this one:

  • __str β€” source string to use

Returns: reference to this string πŸ’–

This function sets this string to the exact contents of __str. __str is a valid, but unspecified string. yes, still unspecified. still don't touch it 🫣

πŸ“ assign β€” set value to contents of a C string ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s) [inline], [constexpr]

Set value to contents of a C string πŸŽ€

  • __s β€” the C string to use

Returns: reference to this string πŸ’–

This function sets the value of this string to the value of __s. The data is copied, so there is no dependence on __s once the function returns. copied!! so you can do whatever you want to __s after, it's not your problem anymore πŸ’…

πŸ“ assign β€” set value to contents of a C string ([inline])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s) [inline]

Set value to contents of a C string. twin overload:

  • __s β€” the C string to use

Returns: reference to this string πŸ’–

This function sets the value of this string to the value of __s. The data is copied, so there is no dependence on __s once the function returns. still copied. still free πŸ¦‹

🧚 assign β€” set value to a C substring ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s, size_type __n) [inline], [constexpr]

Set value to a C substring βœ‚οΈ

  • __s β€” the C string to use
  • __n β€” number of characters to use

Returns: reference to this string πŸ’–

This function sets the value of this string to the first __n characters of __s. If __n is larger than the number of available characters in __s, the remainder of __s is used. it'll take what's there and not complain about it 🌸

🧚 assign β€” set value to a C substring (other variant)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s, size_type __n)

Set value to a C substring. the matching variant:

  • __s β€” the C string to use
  • __n β€” number of characters to use

Returns: reference to this string πŸ’–

This function sets the value of this string to the first __n characters of __s. If __n is larger than the number of available characters in __s, the remainder of __s is used. same rules, bestie, nothing new to learn here 🫢

πŸ’œ assign β€” set value to contents of another string ([inline], [constexpr])

template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::assign (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]

Set value to contents of another string β€” this time it's the const-ref one, so a copy, not a move πŸ‘―

  • __str β€” source string to use

Returns: reference to this string πŸ’–

Referenced by:

  • std::basic_string< _CharT >::assign()
  • std::basic_string< _CharT >::assign()
  • std::basic_string< _CharT >::assign()
  • std::basic_string< _CharT >::operator=()
  • std::basic_string< _CharT >::operator=()
  • std::basic_string< _CharT >::operator=()
  • std::basic_string< _CharT >::operator=()
  • std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow()
  • std::basic_stringbuf< char >::str()
  • std::basic_stringbuf< char >::str()

πŸ’œ assign β€” set value to contents of another string

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const basic_string< _CharT, _Traits, _Alloc > & __str)

Set value to contents of another string. the last one in this batch:

  • __str β€” source string to use

Returns: reference to this string πŸ’–

🫢 assign β€” set this string to a substring of another string 🫢

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
    (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos,
     size_type __n = npos) [inline], [constexpr]

okay bestie so this one is literally "become a slice of somebody else's string". We're in the constexpr era here, slay ✨

  • Parameters
    • __str β€” the string we're stealing from πŸ’…
    • __pos β€” index of the first character of str
    • __n β€” how many characters we're taking
  • Returns β€” a reference to this string (so you can chain, iconic)
  • Exceptions β€” std::out_of_range if pos is not a valid index 😭

The lore: this function sets this string to the substring of __str consisting of __n characters at __pos. And if __n is is larger than the number of available characters in __str, the remainder of __str is used. (yes, "is is", we do not gatekeep typos in this house πŸŽ€)


πŸ’œ assign β€” same thing, but the classic cut πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
    (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos,
     size_type __n = npos) [inline]

Same assignment, no constexpr tag on this one. Set value to a substring of a string, fr fr.

  • Parameters
    • __str β€” the string to use.
    • __pos β€” index of the first character of str.
    • __n β€” number of characters to use.
  • Returns β€” reference to this string 🫢
  • Exceptions β€” std::out_of_range if pos is not a valid index.

This function sets this string to the substring of __str consisting of __n characters at __pos. If __n is is larger than the number of available characters in __str, the remainder of __str is used. Same energy, different vibe check ✨


πŸ¦‹ assign β€” from an initializer_list πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
    (initializer_list< _CharT > __l) [inline], [constexpr]

Set value to an initializer_list of characters. Curly braces girlies rise 🌸

  • Parameters β€” __l β€” the initializer_list of characters to assign.
  • Returns β€” reference to this string. πŸ’–

🧚 assign β€” same, the non-constexpr twin 🧚

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
    (initializer_list< _CharT > __l) [inline]

Set value to an initializer_list of characters.

  • Parameters β€” __l β€” the initializer_list of characters to assign.
  • Returns β€” reference to this string. πŸŽ€

πŸ”₯ assign β€” fill me with N copies of a character πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
    (size_type __n, _CharT __c) [inline], [constexpr]

Set value to multiple characters. You want a string that's just 'x' a hundred times? She's got you, no cap.

  • Parameters
    • __n β€” length of the resulting string.
    • __c β€” the character to use.
  • Returns β€” reference to this string. πŸ‘‘

This function sets the value of this string to __n copies of character __c. That's it, that's the whole thing, periodt.


🌈 assign β€” the duplicate, but make it classic 🌈

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
    (size_type __n, _CharT __c) [inline]

Set value to multiple characters.

  • Parameters
    • __n β€” length of the resulting string.
    • __c β€” the character to use.
  • Returns β€” reference to this string.

This function sets the value of this string to __n copies of character __c. πŸ’œ


⭐ at β€” the safe one, read/write edition ⭐

template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::at (size_type __n)
    [inline], [nodiscard], [constexpr]

Provides access to the data contained in the string. Bounds-checked access, the responsible main character 🫢

  • Parameters β€” __n β€” the index of the character to access.
  • Returns β€” read/write reference to the character.
  • Exceptions β€” std::out_of_range if n is an invalid index. 😭

This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. We love a function that checks before it vibes.


🌸 at β€” safe, and also unshares 🌸

template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::at (size_type __n)
    [inline]

Provides access to the data contained in the string.

  • Parameters β€” __n β€” the index of the character to access.
  • Returns β€” read/write reference to the character.
  • Exceptions β€” std::out_of_range if n is an invalid index.

This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. Success results in unsharing the string. noted bestie πŸ“


πŸ’… at β€” const version, no touching πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::at
    (size_type __n) const [inline], [nodiscard], [constexpr]

Provides access to the data contained in the string. Read-only, hands off, look but don't touch πŸŽ€

  • Parameters β€” __n β€” the index of the character to access.
  • Returns β€” read-only (const) reference to the character.
  • Exceptions β€” std::out_of_range if n is an invalid index.

This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. πŸ‘‘


πŸ¦‹ at β€” const, classic cut πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::at
    (size_type __n) const [inline]

Provides access to the data contained in the string.

  • Parameters β€” __n β€” the index of the character to access.
  • Returns β€” read-only (const) reference to the character.
  • Exceptions β€” std::out_of_range if n is an invalid index.

This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. ✨


πŸ“ back β€” the last character, and you can edit her πŸ“

template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::back () [inline]

Returns a read/write reference to the data at the last element of the string. The final girl, literally 🌸


🧚 back β€” const, nodiscard, constexpr, noexcept 🧚

template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::back () const
    [inline], [nodiscard], [constexpr], [noexcept]

Returns a read-only (constant) reference to the data at the last element of the string. She cannot be changed, she is simply iconic πŸ’–


🌈 back β€” const, noexcept, that's the list 🌈

template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::back () const
    [inline], [noexcept]

Returns a read-only (constant) reference to the data at the last element of the string. 🫢


πŸ‘‘ back β€” read/write, fully decked out in attributes πŸ‘‘

template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::back ()
    [inline], [nodiscard], [constexpr], [noexcept]

Returns a read/write reference to the data at the last element of the string. Go ahead, change the last letter, she won't tell anyone πŸ’…


πŸ”₯ begin β€” iterator to the very first character πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string< _CharT, _Traits, _Alloc >::begin () [inline]

Returns a read/write iterator that points to the first character in the string. Unshares the string. Important, don't skip that part bestie.


⭐ begin β€” const, nodiscard, constexpr, noexcept ⭐

template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::begin () const
    [inline], [nodiscard], [constexpr], [noexcept]

Returns a read-only (constant) iterator that points to the first character in the string. πŸ¦‹


πŸ’œ begin β€” const, noexcept πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::begin () const
    [inline], [noexcept]

Returns a read-only (constant) iterator that points to the first character in the string. πŸŽ€


🌸 begin β€” read/write, and referenced by everyone 🌸

template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string< _CharT, _Traits, _Alloc >::begin ()
    [inline], [nodiscard], [constexpr], [noexcept]

Returns a read/write iterator that points to the first character in the string.

Referenced by std::basic_string< _CharT >::crend(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::regex_match(), std::regex_match(), std::regex_replace(), std::regex_replace(), std::regex_search(), std::basic_string< _CharT >::rend(), std::basic_string< _CharT >::rend(), std::basic_string< _CharT >::rend(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), and std::basic_string< _CharT >::replace().

Look at her, she's the moment, everyone's pulling up to her party 😭✨


πŸŽ€ c_str β€” const pointer to null-terminated contents πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc>
const _CharT * std::basic_string< _CharT, _Traits, _Alloc >::c_str () const
    [inline], [nodiscard], [constexpr], [noexcept]

Return const pointer to null-terminated contents. This is a handle to internal data. Do not modify or dire things may happen. bestie. DO NOT MODIFY. dire things. we mean it. πŸ’€

Referenced by std::__cxx11::collate< _CharT >::do_compare(), std::money_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::__cxx11::collate< _CharT >::do_transform(), std::basic_filebuf< char_type, traits_type >::open(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::regex_replace(), and std::regex_traits< _CharT >::transform_primary().


🧚 c_str β€” same deal, no constexpr tag 🧚

template<typename _CharT, typename _Traits, typename _Alloc>
const _CharT * std::basic_string< _CharT, _Traits, _Alloc >::c_str () const
    [inline], [noexcept]

Return const pointer to null-terminated contents. This is a handle to internal data. Do not modify or dire things may happen. Still true, still scary, still not a drill πŸ™ˆ


πŸ’– capacity β€” how many characters before we need more memory πŸ’–

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::capacity () const
    [inline], [nodiscard], [constexpr], [noexcept]

Returns the total number of characters that the string can hold before needing to allocate more memory. She's got room, she's just not telling you how much of it she's using πŸ‘‘

Referenced by std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::push_back(), reserve(), and reserve().


🌈 capacity β€” classic, noexcept only 🌈

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::capacity () const
    [inline], [noexcept]

Returns the total number of characters that the string can hold before needing to allocate more memory. Same numbers, fewer tags, still slaying ✨


πŸ¦‹ cbegin β€” const iterator to the first character πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::cbegin () const
    [inline], [nodiscard], [constexpr], [noexcept]

Returns a read-only (constant) iterator that points to the first character in the string. The c stands for "const, bestie, calm down" πŸ’…


πŸŽ€ cbegin β€” the other one, no constexpr πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::cbegin () const
    [inline], [noexcept]

Returns a read-only (constant) iterator that points to the first character in the string. 🫢


⭐ cend β€” const iterator, one past the last character ⭐

template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::cend () const
    [inline], [nodiscard], [constexpr], [noexcept]

Returns a read-only (constant) iterator that points one past the last character in the string. Yes, one past the last β€” that's the whole point of an end iterator, she's the afterparty, not a guest 🌸

πŸ’« cend()

template<typename _CharT, typename _Traits, typename _Alloc> const_iterator
    std::basic_string< _CharT, _Traits, _Alloc >::cend () const

Attributes: [inline], [noexcept]

ok so cend() is the read-only bestie of end(). It hands you a constant iterator that points one past the last character in the string. That's it, that's the whole job β€” it's the "nothing to see here, and also don't touch anything" iterator. πŸŽ€

Reminder bestie: "one past the last character" means you can never dereference it. It's a fence post, not a sheep. πŸ‘

🧹 clear() β€” the constexpr edition

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::clear ()

Attributes: [inline], [constexpr], [noexcept]

Erases the string. Makes it empty. Poof, gone, nothing left, the string is now a whole vibe of void. ✨

Referenced by std::__cxx11::collate< _CharT >::do_transform(), and std::basic_string< _CharT >::operator=().


🧹 clear() β€” the non-constexpr edition

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::clear ()

Attributes: [inline], [noexcept]

Same exact energy, just without the constexpr sparkle. Erases the string, making it empty. πŸ’…


βš–οΈ compare() vs a C string β€” version one

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (const _CharT *
    __s) const

Attributes: [inline], [nodiscard], [constexpr], [noexcept]

Compare to a C string. πŸ¦‹

Parameters

  • __s β€” C string to compare against.

Returns

  • Integer < 0, 0, or > 0.

Returns an integer < 0 if this string is ordered before __s, 0 if their values are equivalent, or > 0 if this string is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of size() and the length of a string constructed from __s. The function then compares the two strings by calling traits::compare(data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. πŸ‘‘


βš–οΈ compare() vs a C string β€” version two

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (const _CharT *
    __s) const

Attributes: [inline], [noexcept]

Compare to a C string. Same deal, no nodiscard, no constexpr. πŸŽ€

Parameters

  • __s β€” C string to compare against.

Returns

  • Integer < 0, 0, or > 0.

Returns an integer < 0 if this string is ordered before __s, 0 if their values are equivalent, or > 0 if this string is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of size() and the length of a string constructed from __s. The function then compares the two strings by calling traits::compare(data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.


πŸͺž compare() vs a string β€” version one

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (const
    basic_string< _CharT, _Traits, _Alloc > & __str) const

Attributes: [inline], [nodiscard], [constexpr]

Compare to a string. πŸ’–

Parameters

  • __str β€” String to compare against.

Returns

  • Integer < 0, 0, or > 0.

Returns an integer < 0 if this string is ordered before __str, 0 if their values are equivalent, or > 0 if this string is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of size() and str.size(). The function then compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. ⭐


πŸͺž compare() vs a string β€” version two

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (const
    basic_string< _CharT, _Traits, _Alloc > & __str) const

Attributes: [inline]

Compare to a string. Yep, the bare-bones twin. 🌸

Parameters

  • __str β€” String to compare against.

Returns

  • Integer < 0, 0, or > 0.

Returns an integer < 0 if this string is ordered before __str, 0 if their values are equivalent, or > 0 if this string is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of size() and str.size(). The function then compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.


βœ‚οΈ compare() β€” substring vs a string, version one

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
    size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
    const

Attributes: [inline], [nodiscard], [constexpr]

Compare substring to a string. Now we're getting fancy. 🧚

Parameters

  • __pos β€” Index of first character of substring.
  • __n β€” Number of characters in substring.
  • __str β€” String to compare against.

Returns

  • Integer < 0, 0, or > 0.

Form the substring of this string from the __n characters starting at __pos. Returns an integer < 0 if the substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). The function then compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. πŸ’«


βœ‚οΈ compare() β€” substring vs a string, version two

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
    size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
    const

Attributes: [inline]

Compare substring to a string. The un-sprinkled one. πŸŽ€

Parameters

  • __pos β€” Index of first character of substring.
  • __n β€” Number of characters in substring.
  • __str β€” String to compare against.

Returns

  • Integer < 0, 0, or > 0.

Form the substring of this string from the __n characters starting at __pos. Returns an integer < 0 if the substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). The function then compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.


🌿 compare() β€” substring vs a C string, version one

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
    size_type __n1, const _CharT * __s) const

Attributes: [inline], [nodiscard], [constexpr]

Compare substring to a C string. πŸ¦‹

Parameters

  • __pos β€” Index of first character of substring.
  • __n1 β€” Number of characters in substring.
  • __s β€” C string to compare against.

Returns

  • Integer < 0, 0, or > 0.

Form the substring of this string from the __n1 characters starting at pos. Returns an integer < 0 if the substring is ordered before __s, 0 if their values are equivalent, or > 0 if the substring is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and the length of a string constructed from __s. The function then compares the two string by calling traits::compare(substring.data(),__s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. ✨


🌿 compare() β€” substring vs a C string, version two

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
    size_type __n1, const _CharT * __s) const

Attributes: [inline]

Compare substring to a C string. Again, the plain twin. πŸ’œ

Parameters

  • __pos β€” Index of first character of substring.
  • __n1 β€” Number of characters in substring.
  • __s β€” C string to compare against.

Returns

  • Integer < 0, 0, or > 0.

Form the substring of this string from the __n1 characters starting at pos. Returns an integer < 0 if the substring is ordered before __s, 0 if their values are equivalent, or > 0 if the substring is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and the length of a string constructed from __s. The function then compares the two string by calling traits::compare(substring.data(),__s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.


πŸ”€ compare() β€” substring vs a character array, version one

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
    size_type __n1, const _CharT * __s, size_type __n2) const

Attributes: [inline], [nodiscard], [constexpr]

Compare substring against a character array. No null terminator energy here, just vibes and a length. πŸ”₯

Parameters

  • __pos β€” Index of first character of substring.
  • __n1 β€” Number of characters in substring.
  • __s β€” character array to compare against.
  • __n2 β€” Number of characters of s.

Returns

  • Integer < 0, 0, or > 0.

Form the substring of this string from the __n1 characters starting at __pos. Form a string from the first __n2 characters of __s. Returns an integer < 0 if this substring is ordered before the string from __s, 0 if their values are equivalent, or > 0 if this substring is ordered after the string from __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __n2. The function then compares the two strings by calling traits::compare(substring.data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. πŸ‘‘

NB: s must have at least n2 characters, '\0' has no special meaning. 🚨 bestie this one is serious β€” that null byte is NOT gonna save you here, it's just a regular character like everybody else. πŸ’€

πŸ”€ compare() β€” substring vs a character array, version two

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
    size_type __n1, const _CharT * __s, size_type __n2) const

Attributes: [inline]

Compare substring against a character array. Same function, fewer attributes, same rules. 🌈

Parameters

  • __pos β€” Index of first character of substring.
  • __n1 β€” Number of characters in substring.
  • __s β€” character array to compare against.
  • __n2 β€” Number of characters of s.

Returns

  • Integer < 0, 0, or > 0.

Form the substring of this string from the __n1 characters starting at __pos. Form a string from the first __n2 characters of __s. Returns an integer < 0 if this substring is ordered before the string from __s, 0 if their values are equivalent, or > 0 if this substring is ordered after the string from __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __n2. The function then compares the two strings by calling traits::compare(substring.data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.

NB: s must have at least n2 characters, '\0' has no special meaning. 🚨 Still true, still not joking around. πŸ™ˆ

πŸŽ€ compare() β€” substring vs a substring

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos1,
    size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
    size_type __pos2, size_type __n2 = npos) const

Attributes: [inline], [nodiscard], [constexpr]

Compare substring to a substring. πŸ’…

Parameters

  • __pos1 β€” index of the first character of the substring 🫢
  • __n1 β€” how many characters are in the substring
  • __str β€” the string we're comparing against, bestie
  • __pos2 β€” index of the first character of the substring of str
  • __n2 β€” number of characters in that substring of str

Returns

Integer < 0, 0, or > 0. (classic three-way comparison, she ate)

Form the substring of this string from the __n1 characters starting at __pos1. Form the substring of __str from the __n2 characters starting at __pos2. Returns an integer < 0 if this substring is ordered before the substring of __str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of __str. Determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. The function then compares the two strings by calling

traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen)

If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first. so simple, so iconic ✨


Compare substring to a substring 🌸

template<typename _CharT, typename _Traits, typename _Alloc> int
    std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos1,
    size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
    size_type __pos2, size_type __n2 = npos) const [inline]

Compare substring to a substring. Yeah, she's back for round two, no cap πŸ’…

Parameters

  • __pos1 β€” index of the first character of the substring
  • __n1 β€” number of characters in the substring
  • __str β€” the string to compare against
  • __pos2 β€” index of the first character of the substring of str
  • __n2 β€” number of characters in the substring of str

Returns

Integer < 0, 0, or > 0.

Form the substring of this string from the __n1 characters starting at __pos1. Form the substring of __str from the __n2 characters starting at __pos2. Returns an integer < 0 if this substring is ordered before the substring of __str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of __str. Determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. The function then compares the two strings by calling

traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen)

If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first.


copy β€” copy substring into a C string πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
    _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
    _Alloc >::copy (_CharT * __s, size_type __n, size_type __pos = 0) const
    [constexpr]

Parameters

  • __s β€” the C string you're copying the value into
  • __n β€” number of characters to copy
  • __pos β€” index of the first character to copy

Returns

Number of characters actually copied. (yes, actually β€” she keeps it real)

Exceptions

  • std::out_of_range β€” if __pos > size().

Copies up to __n characters starting at __pos into the C string __s. If __pos is greater than size(), out_of_range is thrown. so if you're out here passing a position past the end, she WILL throw, and honestly? deserved.


copy (the non-constexpr twin) πŸ’–

template<typename _CharT, typename _Traits, typename _Alloc> size_type
    std::basic_string< _CharT, _Traits, _Alloc >::copy (_CharT * __s,
    size_type __n, size_type __pos = 0) const

Copy substring into C string.

Parameters

  • __s β€” C string to copy value into
  • __n β€” number of characters to copy
  • __pos β€” index of first character to copy

Returns

Number of characters actually copied

Exceptions

  • std::out_of_range β€” if __pos > size().

Copies up to __n characters starting at __pos into the C string __s. If __pos is greater than size(), out_of_range is thrown.


crbegin β€” reverse iterator, but make it read-only πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::crbegin () const [inline],  [nodiscard],  [constexpr],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last character in the string. Iteration is done in reverse element order. walking backwards through your string, but respectfully and with no editing privileges πŸ‘‘


crbegin (again, minus the sparkle tags)

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::crbegin () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last character in the string. Iteration is done in reverse element order.


crend β€” the other end of the reverse walk 🌈

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::crend () const [inline],  [nodiscard],  [constexpr],  [noexcept]

Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order.


crend (the other other one) ✨

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::crend () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order.


data β€” gimme that pointer 🫢

template<typename _CharT, typename _Traits, typename _Alloc> const _CharT *
    std::basic_string< _CharT, _Traits, _Alloc >::data () const [inline],
    [nodiscard],  [constexpr],  [noexcept]

Return const pointer to contents. This is a pointer to internal data. It is undefined to modify the contents through the returned pointer. To get a pointer that allows modifying the contents use &str[0] instead, (or in C++17 the non-const str.data() overload).

okay bestie listen β€” DO NOT write through this pointer. it's giving "const for a reason." if you touch the bytes you're in undefined behaviour territory and she did not consent πŸ’€

Referenced by std::basic_regex< char >::assign(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::__cxx11::collate< _CharT >::do_compare(), std::__cxx11::collate< _CharT >::do_transform(), std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find_first_not_of(), std::basic_string< _CharT >::find_first_of(), std::basic_string< _CharT >::find_last_of(), std::match_results< _BidirectionalIterator, polymorphic_allocator< sub_match< _BidirectionalIterator > > >< const char * >::format(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::from_bytes(), std::operator==(), std::basic_stringbuf< char >::str(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::to_bytes(), and std::regex_traits< _CharT >::transform(). she's popular, she's booked, she's everywhere fr fr


data (const edition, no frills)

template<typename _CharT, typename _Traits, typename _Alloc> const _CharT *
    std::basic_string< _CharT, _Traits, _Alloc >::data () const [inline],
    [noexcept]

Return const pointer to contents. This is a pointer to internal data. It is undefined to modify the contents through the returned pointer. To get a pointer that allows modifying the contents use &str[0] instead, (or in C++17 the non-const str.data() overload).


data β€” now non-const, now editable πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc> _CharT *
    std::basic_string< _CharT, _Traits, _Alloc >::data () [inline],
    [nodiscard],  [constexpr],  [noexcept]

Return non-const pointer to contents. This is a pointer to the character sequence held by the string. Modifying the characters in the sequence is allowed. glow up unlocked ✨


data (non-const, plain) 🌸

template<typename _CharT, typename _Traits, typename _Alloc> _CharT *
    std::basic_string< _CharT, _Traits, _Alloc >::data () [inline]

Return non-const pointer to contents. This is a pointer to the character sequence held by the string. Modifying the characters in the sequence is allowed.

The standard requires this function to be noexcept but for the Copy-On-Write string implementation it can throw. This function allows modifying the string contents directly, which means we must copy-on-write to unshare it, which requires allocating memory.

and there it is β€” the plot twist. the standard says noexcept, but COW strings said "not today." if you're on a COW implementation, that innocent-looking call can allocate, and allocating can throw. iykyk 😭

empty β€” is it giving nothing? πŸ’€

template<typename _CharT, typename _Traits, typename _Alloc> bool
    std::basic_string< _CharT, _Traits, _Alloc >::empty () const [inline],
    [nodiscard],  [constexpr],  [noexcept]

Returns true if the string is empty. Equivalent to *this == "".

Referenced by std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::front(), std::basic_string< _CharT >::front(), std::basic_string< _CharT >::front(), std::regex_traits< _Ch_type >::lookup_collatename(), std::tr2::operator>>(), std::basic_string< _CharT >::pop_back(), and std::basic_string< _CharT >::pop_back().


empty (again, for the people in the back) πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc> bool
    std::basic_string< _CharT, _Traits, _Alloc >::empty () const [inline],
    [nodiscard],  [noexcept]

Returns true if the string is empty. Equivalent to *this == "".


end β€” the classic one-past-the-end πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc> iterator
    std::basic_string< _CharT, _Traits, _Alloc >::end () [inline]

Returns a read/write iterator that points one past the last character in the string. Unshares the string. (yes girl, that means it might do COW things behind your back πŸ‘€)


end (const, fully decked out)

template<typename _CharT, typename _Traits, typename _Alloc> const_iterator
    std::basic_string< _CharT, _Traits, _Alloc >::end () const [inline],
    [nodiscard],  [constexpr],  [noexcept]

Returns a read-only (constant) iterator that points one past the last character in the string.


end (const, minimal)

template<typename _CharT, typename _Traits, typename _Alloc> const_iterator
    std::basic_string< _CharT, _Traits, _Alloc >::end () const [inline],
    [noexcept]

Returns a read-only (constant) iterator that points one past the last character in the string.


end (non-const, decorated) πŸ‘‘

template<typename _CharT, typename _Traits, typename _Alloc> iterator
    std::basic_string< _CharT, _Traits, _Alloc >::end () [inline],
    [nodiscard],  [constexpr],  [noexcept]

Returns a read/write iterator that points one past the last character in the string.

Referenced by std::basic_string< _CharT >::append(), std::basic_string< _CharT >::crbegin(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::rbegin(), std::basic_string< _CharT >::rbegin(), std::basic_string< _CharT >::rbegin(), std::regex_match(), std::regex_match(), std::regex_replace(), std::regex_replace(), std::regex_search(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), and std::basic_string< _CharT >::replace(). the way literally every algorithm needs her... main character energy, no notes 🌈


erase β€” remove a range of characters πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc> iterator
    std::basic_string< _CharT, _Traits, _Alloc >::erase (__const_iterator
    __first, __const_iterator __last) [inline],  [constexpr]

Remove a range of characters.

Parameters

  • __first β€” iterator referencing the first character to remove
  • __last β€” iterator referencing the end of the range

Returns

Iterator referencing location of first after removal.

Removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. strong exception guarantee, she's safe, she's stable, she's that girl πŸ’–


erase β€” remove one character πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc> iterator
    std::basic_string< _CharT, _Traits, _Alloc >::erase (__const_iterator
    __position) [inline],  [constexpr]

Remove one character.

Parameters

  • __position β€” iterator referencing the character to remove

Returns β€” iterator referencing same location after removal. πŸ’«

Removes the character at __position from this string. The value of the string doesn't change if an error is thrown. No cap, your string stays exactly as it was if something goes sideways.


πŸ’… iterator erase(iterator __first, iterator __last)

Remove a range of characters. bye-bye besties, a whole squad of them 🫢

Parameters

  • __first β€” Iterator referencing the first character to remove.
  • __last β€” Iterator referencing the end of the range.

Returns

  • Iterator referencing location of first after removal.

Removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. Obsessed with how safe this is ngl.


✨ iterator erase(iterator __position) [inline]

Remove one character. just the one, a lil solo moment πŸŽ€

Parameters

  • __position β€” Iterator referencing the character to remove.

Returns

  • iterator referencing same location after removal.

Removes the character at __position from this string. The value of the string doesn't change if an error is thrown. πŸ’–


🌸 basic_string & erase(size_type __pos = 0, size_type __n = npos) [inline], [constexpr]

Remove characters. the index-based edition, very demure, very mindful

Parameters

  • __pos β€” Index of first character to remove (default 0).
  • __n β€” Number of characters to remove (default remainder).

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos is beyond the end of this string. 🚨

Removes __n characters from this string starting at __pos. The length of the string is reduced by __n. If there are < __n characters to remove, the remainder of the string is truncated. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown. Translation: it either fully does the thing or fully doesn't, no half-finished chaos here.

Referenced by std::getline(), std::operator>>(), std::basic_string< _CharT >::pop_back(), and resize(). πŸ‘‘


🌈 basic_string & erase(size_type __pos = 0, size_type __n = npos) [inline]

Remove characters. same energy, different flag set ✨

Parameters

  • __pos β€” Index of first character to remove (default 0).
  • __n β€” Number of characters to remove (default remainder).

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos is beyond the end of this string. 🚨

Removes __n characters from this string starting at __pos. The length of the string is reduced by __n. If there are < __n characters to remove, the remainder of the string is truncated. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown. πŸ’œ


πŸ¦‹ size_type find(_CharT __c, size_type __pos = 0) const [nodiscard], [constexpr], [noexcept]

Find position of a character. where u at girl πŸ”

Parameters

  • __c β€” Character to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of first occurrence.

Starting from __pos, searches forward for __c within this string. If found, returns the index where it was found. If not found, returns npos. And yes bestie, [nodiscard] means the compiler WILL side-eye you if you ignore the answer. Don't do it.

References npos, and std::size().


⭐ size_type find(_CharT __c, size_type __pos = 0) const [noexcept]

Find position of a character. the remix πŸ’…

Parameters

  • __c β€” Character to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of first occurrence.

Starting from __pos, searches forward for __c within this string. If found, returns the index where it was found. If not found, returns npos. πŸ“


πŸ”₯ size_type find(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]

Find position of a C substring. C-string coded but make it specific

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to search from.
  • __n β€” Number of characters from s to search for.

Returns

  • Index of start of first occurrence.

Starting from __pos, searches forward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos. πŸ’€

References std::data(), npos, and std::size().

Referenced by std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find(), and std::basic_string< _CharT >::find_first_of(). (yes, find() shows up three times, she's popular, iykyk)


🧚 size_type find(const _CharT * __s, size_type __pos, size_type __n) const [noexcept]

Find position of a C substring. encore ✨

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to search from.
  • __n β€” Number of characters from s to search for.

Returns

  • Index of start of first occurrence.

Starting from __pos, searches forward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos. πŸ¦‹


πŸ‘‘ size_type find(const _CharT * __s, size_type __pos = 0) const [inline], [nodiscard], [constexpr], [noexcept]

Find position of a C string. the whole string, no slicing required

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of start of first occurrence.

Starting from __pos, searches forward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos. 🌈


🌸 size_type find(const _CharT * __s, size_type __pos = 0) const [inline], [noexcept]

Find position of a C string. ok and again for the people in the back πŸ“£

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of start of first occurrence.

Starting from __pos, searches forward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos. πŸ’–


πŸŽ€ size_type find(const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const [inline], [nodiscard], [constexpr], [noexcept]

Find position of a string. string looking for string, so meta πŸ’…

Parameters

  • __str β€” String to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of start of first occurrence.

Starting from __pos, searches forward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos. ⭐


πŸ’œ size_type find(const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const [inline], [noexcept]

Find position of a string. the twin, no [nodiscard] invited to this one

Parameters

  • __str β€” String to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of start of first occurrence.

Starting from __pos, searches forward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos. πŸ™ˆ


πŸ“ size_type find_first_not_of(_CharT __c, size_type __pos = 0) const [nodiscard], [constexpr], [noexcept]

Find position of a different character. not like the other girls πŸŽ€

Parameters

  • __c β€” Character to avoid.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of first occurrence.

Starting from __pos, searches forward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos. Basically: "first one that isn't this one, please."

References npos, and std::size().


✨ size_type find_first_not_of(_CharT __c, size_type __pos = 0) const [noexcept]

Find position of a different character. round two, still not like the others πŸ’«

Parameters

  • __c β€” Character to avoid.
  • __pos β€” Index of character to search from (default 0).

Returns

  • Index of first occurrence.

Starting from __pos, searches forward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos. πŸ’œ


πŸ¦‹ size_type find_first_not_of(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]

Find position of a character not in C substring. a whole lil C-string of characters to avoid, dramatic πŸ’…

Parameters

  • __s β€” C string containing characters to avoid.
  • __pos β€” Index of character to search from.
  • __n β€” Number of characters from __s to consider.

Returns

  • Index of first occurrence.

Starting from __pos, searches forward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos. πŸ”₯

References npos, and std::size().


🌈 size_type find_first_not_of(const _CharT * __s, size_type __pos, size_type __n) const [noexcept]

Find position of a character not in C substring. same quest, different tag

Parameters

  • __s β€” C string containing characters to avoid.
  • __pos β€” Index of character to search from.
  • __n β€” Number of characters from __s to consider.

Returns

  • Index of first occurrence.

Starting from __pos, searches forward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos. πŸ‘‘


🌸 size_type find_first_not_of(const _CharT * __s, size_type __pos = 0) const [inline], [nodiscard], [constexpr], [noexcept]

Find position of a character not in C string. the whole C-string this time, no __n needed

Parameters

  • __s β€” C string containing characters to avoid.
  • __pos β€” Index of character to search from (default 0).

…and that index is the index of the first occurrence. πŸ’–


find_first_not_of β€” the C-string edition

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_not_of(const _CharT *__s, size_type __pos = 0) const

[inline], [noexcept]

Find position of a character not in C string. ✨

Parameters

  • __s β€” the C string holding all the characters you want to avoid, bestie. Like a little list of nopes. πŸ™ˆ
  • __pos β€” index of the character to start searching from (defaults to 0, so like, the very beginning).

Returns

Index of first occurrence.

So starting from __pos, it searches forward for a character that is not contained in __s within this string. Found one? Slay, it hands you back the index where it lives. Not found? You get npos. πŸ’€


find_first_not_of β€” the basic_string edition (the constexpr one πŸ‘‘)

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const

[inline], [nodiscard], [constexpr], [noexcept]

Find position of a character not in string. πŸ¦‹

Parameters

  • __str β€” the string containing the characters to avoid.
  • __pos β€” index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos.

Referenced by std::basic_string< _CharT >::find_first_not_of(), std::basic_string< _CharT >::find_first_not_of(), and std::basic_string< _CharT >::find_first_not_of().


find_first_not_of β€” the basic_string edition (non-constexpr twin)

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const

[inline], [noexcept]

Find position of a character not in string. 🌸

Parameters

  • __str β€” string containing characters to avoid.
  • __pos β€” index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos.


find_first_of β€” single char, constexpr girlie πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(_CharT __c, size_type __pos = 0) const

[inline], [nodiscard], [constexpr], [noexcept]

Find position of a character. ⭐

Parameters

  • __c β€” the character to locate.
  • __pos β€” index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for the character __c within this string. If found, returns the index where it was found. If not found, returns npos.

Note: equivalent to find(__c, __pos). same thing, different font. πŸ’–

find_first_of β€” single char, the other one

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(_CharT __c, size_type __pos = 0) const

[inline], [noexcept]

Find position of a character. πŸŽ€

Parameters

  • __c β€” Character to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for the character __c within this string. If found, returns the index where it was found. If not found, returns npos.

Note: equivalent to find(__c, __pos).

find_first_of β€” C substring, constexpr edition

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos, size_type __n) const

[nodiscard], [constexpr], [noexcept]

Find position of a character of C substring. πŸ”₯

Parameters

  • __s β€” string containing characters to locate.
  • __pos β€” index of character to search from.
  • __n β€” number of characters from s to search for.

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.

References npos, and std::size().


find_first_of β€” C substring, non-constexpr twin

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos, size_type __n) const

[noexcept]

Find position of a character of C substring. 🧚

Parameters

  • __s β€” string containing characters to locate.
  • __pos β€” index of character to search from.
  • __n β€” number of characters from s to search for.

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.


find_first_of β€” whole C string, constexpr

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos = 0) const

[inline], [nodiscard], [constexpr], [noexcept]

Find position of a character of C string. πŸ’œ

Parameters

  • __s β€” string containing characters to locate.
  • __pos β€” index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.


find_first_of β€” whole C string, the twin

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos = 0) const

[inline], [noexcept]

Find position of a character of C string. 🌈

Parameters

  • __s β€” string containing characters to locate.
  • __pos β€” index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.


find_first_of β€” basic_string flavor, constexpr girlie

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const

[inline], [nodiscard], [constexpr], [noexcept]

Find position of a character of string. ✨

Parameters

  • __str β€” string containing characters to locate.
  • __pos β€” index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.

Referenced by std::basic_string< _CharT >::find_first_of(), and std::basic_string< _CharT >::find_first_of().


find_first_of β€” basic_string flavor, the twin

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const

[inline], [noexcept]

Find position of a character of string. 🌸

Parameters

  • __str β€” string containing characters to locate.
  • __pos β€” index of character to search from (default 0).

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.


find_last_not_of β€” single char, searching backwards πŸ”™

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(_CharT __c, size_type __pos = npos) const

[nodiscard], [constexpr], [noexcept]

Find last position of a different character. πŸ’–

Parameters

  • __c β€” character to avoid.
  • __pos β€” index of character to search back from (default end).

Returns

Index of last occurrence.

Starting from __pos, searches backward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.

References npos, and std::size().


find_last_not_of β€” single char, the twin

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(_CharT __c, size_type __pos = npos) const

[noexcept]

Find last position of a different character. πŸ¦‹

Parameters

  • __c β€” character to avoid.
  • __pos β€” index of character to search back from (default end).

Returns

Index of last occurrence.

Starting from __pos, searches backward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.


find_last_not_of β€” C substring, constexpr edition

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos, size_type __n) const

[nodiscard], [constexpr], [noexcept]

Find last position of a character not in C substring. πŸ”₯

Parameters

  • __s β€” C string containing characters to avoid.
  • __pos β€” index of character to search back from.
  • __n β€” number of characters from s to consider.

Returns

Index of last occurrence.

Starting from __pos, searches backward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.

References npos, and std::size().


find_last_not_of β€” C substring, the twin

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos, size_type __n) const

[noexcept]

Find last position of a character not in C substring. 🧚

Parameters

  • __s β€” C string containing characters to avoid.
  • __pos β€” index of character to search back from.
  • __n β€” number of characters from s to consider.

Returns

Index of last occurrence.

Starting from __pos, searches backward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.


find_last_not_of β€” whole C string, constexpr edition

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos = npos) const

[inline], [nodiscard], [constexpr], [noexcept]

Find last position of a character not in C string. 🌈

Parameters

  • __s β€” C string containing characters to avoid.
  • __pos β€” index of character to search back from (default end).

Returns

Index of last occurrence.

Starting from __pos, searches backward for a character not contained in __s within this string. If found, returns the index where it was found. If not found, returns npos.


🌸 find_last_not_of β€” the "who here is NOT on the list" detector

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos = npos) const

[inline], [noexcept]

Find last position of a character not in C string.

Parameters

  • __s β€” a C string stuffed with the characters you wanna avoid, bestie.
  • __pos β€” the index of the character you start searching back from (default is the end, npos).

Returns

Index of the last occurrence. πŸ’…

okay so real talk: it starts at __pos and walks backward through this string, hunting for a character that is not contained in __s. Found one? Slay, it returns the index where it lives. Not found? It hands you npos and you gotta deal with it. 😭


✨ find_last_not_of β€” string version (the fancy one)

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const

[inline], [nodiscard], [constexpr], [noexcept]

Find last position of a character not in string.

Parameters

  • __str β€” the string holding all the characters you're avoiding.
  • __pos β€” index of the character to search back from (default is the end).

Returns

Index of the last occurrence. 🌟

Starting from __pos, it searches backward for a character that is not contained in __str within this string. Found it? Returns the index. Not found? npos, and honestly, same. πŸ™ˆ

🫢 lowkey referenced by std::basic_string<_CharT>::find_last_not_of(), std::basic_string<_CharT>::find_last_not_of(), and std::basic_string<_CharT, std::char_traits<_CharT>, std::allocator<_CharT>>::swap().

πŸ’œ find_last_not_of β€” string version, the remix

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const

[inline], [noexcept]

Find last position of a character not in string.

Parameters

  • __str β€” string containing the characters to avoid.
  • __pos β€” index of the character to search back from (default end).

Returns

Index of the last occurrence.

Same energy as above, fr fr: start at __pos, walk backward, find a character that is not in __str. Gotcha index? Returned. No dice? npos. Periodt.


πŸŽ€ find_last_of β€” single character edition

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(_CharT __c, size_type __pos = npos) const

[inline], [nodiscard], [constexpr], [noexcept]

Find last position of a character.

Parameters

  • __c β€” the character you're locating.
  • __pos β€” index of the character to search back from (default end).

Returns

Index of the last occurrence. ✨

Starting from __pos, it searches backward for __c within this string. Found it? Returns the index where it was found. Not found? npos. That's the whole vibe check.

πŸ’… Note: equivalent to rfind(__c, __pos).

🌈 find_last_of β€” single character, the remix

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(_CharT __c, size_type __pos = npos) const

[inline], [noexcept]

Find last position of a character.

Parameters

  • __c β€” character to locate.
  • __pos β€” index of the character to search back from (default end).

Returns

Index of the last occurrence.

Starts at __pos, goes backward looking for __c. Found β†’ index. Not found β†’ npos. No cap. 🧚

πŸ’… Note: equivalent to rfind(__c, __pos).

πŸ¦‹ find_last_of β€” C substring, first __n chars only

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos, size_type __n) const

[nodiscard], [constexpr], [noexcept]

Find last position of a character of C substring.

Parameters

  • __s β€” C string containing the characters you wanna locate.
  • __pos β€” index of the character to search back from.
  • __n β€” number of characters from s to search for. πŸ‘€

Returns

Index of the last occurrence.

Starting from __pos, it searches backward for one of the first __n characters of __s within this string. Found one? Returns the index where it was found. Not found? npos, bestie.

🫢 References npos, and std::size().

🌸 find_last_of β€” C substring, unadorned version

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos, size_type __n) const

[noexcept]

Find last position of a character of C substring.

Parameters

  • __s β€” C string containing characters to locate.
  • __pos β€” index of the character to search back from.
  • __n β€” number of characters from s to search for.

Returns

Index of the last occurrence.

Same deal: from __pos, search backward for one of the first __n characters of __s in this string. Found β†’ index. Not found β†’ npos. πŸ’–


πŸ‘‘ find_last_of β€” C string, default pos

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos = npos) const

[inline], [nodiscard], [constexpr], [noexcept]

Find last position of a character of C string.

Parameters

  • __s β€” C string containing the characters to locate.
  • __pos β€” index of the character to search back from (default end).

Returns

Index of the last occurrence.

Starting from __pos, it searches backward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos. Iconic behaviour tbh.


⭐ find_last_of β€” C string, the remix

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos = npos) const

[inline], [noexcept]

Find last position of a character of C string.

Parameters

  • __s β€” C string containing characters to locate.
  • __pos β€” index of the character to search back from (default end).

Returns

Index of the last occurrence.

Same as above, no frills: search backward from __pos for one of the chars in __s. Found β†’ index, not found β†’ npos. πŸ’œ


πŸ“ find_last_of β€” string version

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const

[inline], [nodiscard], [constexpr], [noexcept]

Find last position of a character of string.

Parameters

  • __str β€” string containing the characters to locate.
  • __pos β€” index of the character to search back from (default end).

Returns

Index of the last occurrence.

Starting from __pos, it searches backward for one of the characters of __str within this string. Found β†’ returns the index where it was found. Not found β†’ npos. Simple as that. ✨

🫢 Referenced by std::basic_string<_CharT>::find_last_of(), and std::basic_string<_CharT>::find_last_of().

🧚 find_last_of β€” string version, the remix

template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const

[inline], [noexcept]

Find last position of a character of string.

Parameters

  • __str β€” string containing characters to locate.
  • __pos β€” index of the character to search back from (default end).

Returns

Index of the last occurrence.

Search backward from __pos for one of the characters of __str. Found β†’ index. Not found β†’ npos. That's it, that's the function. πŸ’…


🌟 front β€” the read/write version

template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string<_CharT, _Traits, _Alloc>::front()

[inline]

Returns a read/write reference to the data at the first element of the string. Yes bestie, you can literally write to it. Main character energy. πŸ‘‘


πŸ’– front β€” the const version, fully loaded

template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string<_CharT, _Traits, _Alloc>::front() const

[inline], [nodiscard], [constexpr], [noexcept]

Returns a read-only (constant) reference to the data at the first element of the string. Look but don't touch, babe. πŸ™ˆ


πŸ’œ front β€” the const version, the remix

template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string<_CharT, _Traits, _Alloc>::front() const

[inline], [noexcept]

Returns a read-only (constant) reference to the data at the first element of the string.


πŸ”₯ front β€” read/write, fully loaded

template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string<_CharT, _Traits, _Alloc>::front()

[inline], [nodiscard], [constexpr], [noexcept]

Returns a read/write reference to the data at the first element of the string. Go off, edit that first char. πŸŽ€


πŸŽ€ get_allocator β€” who made you

template<typename _CharT, typename _Traits, typename _Alloc>
allocator_type std::basic_string<_CharT, _Traits, _Alloc>::get_allocator() const

[inline], [nodiscard], [constexpr], [noexcept]

Return copy of allocator used to construct this string. It's giving "let me see your birth certificate" but make it wholesome. 🌸

🫢 Referenced by std::basic_string<_CharT>::~basic_string(), std::basic_string<_CharT>::assign(), std::basic_string<_CharT>::clear(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), reserve(), reserve(), and swap().

✨ get_allocator β€” the remix

template<typename _CharT, typename _Traits, typename _Alloc>
allocator_type std::basic_string<_CharT, _Traits, _Alloc>::get_allocator() const

[inline], [noexcept]

Return copy of allocator used to construct this string. Same allocator lore, same copy, no notes. πŸ’…


πŸ’… insert β€” drop one character in

template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::insert(__const_iterator __p, _CharT __c)

[inline], [constexpr]

Insert one character.

Parameters

  • __p β€” iterator referencing the position in the string to insert at.
  • __c β€” the character to insert.

Returns

Iterator referencing the newly inserted char. ✨

Exceptions

  • std::length_error β€” if the new length exceeds max_size().

Inserts character __c at the position referenced by __p. If adding the character causes the length to exceed max_size(), length_error gets thrown. If __p is beyond the end of the string, out_of_range gets thrown. And listen β€” the value of the string doesn't change if an error is thrown. So no half-finished messes. 🫢


🌈 insert β€” drop a whole range in

template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
iterator std::basic_string<_CharT, _Traits, _Alloc>::insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)

[inline], [constexpr]

Insert a range of characters.

Parameters

  • __p β€” const_iterator referencing the location in the string to insert at.
  • __beg β€” start of the range.
  • __end β€” end of the range.

Returns

Iterator referencing the first inserted char. 🌟

Exceptions

  • std::length_error β€” if the new length exceeds max_size().

Inserts the characters in the range [beg,end). If adding those characters causes the length to exceed max_size(), length_error gets thrown. And again, bestie: the value of the string doesn't change if an error is thrown. Nothing changes, no chaos, just vibes. πŸ’–

okay so insert() is literally the friend who shows up to every party with a plus-one, a plus-two, and a whole plus-entourage 😭 there are SO many overloads and they all do basically the same vibe: drop some characters in at a spot you pick. let's go one by one, no skipping, bestie πŸ’…


template<typename _CharT, typename _Traits, typename _Alloc>
iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (const_iterator __p, initializer_list< _CharT > __l) [inline], [constexpr]

Insert an initializer_list of characters. basically a little bundle of chars walks in and sits down at __p πŸŽ€

Parameters

  • __p β€” Iterator referencing location in string to insert at.
  • __l β€” The initializer_list of characters to insert.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

template<typename _CharT, typename _Traits, typename _Alloc>
iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (const_iterator __p, size_type __n, _CharT __c) [inline], [constexpr]

Insert multiple characters. same character, __n times, over and over, like a group chat spam πŸ’€

Parameters

  • __p β€” Const_iterator referencing location in string to insert at.
  • __n β€” Number of characters to insert
  • __c β€” The character to insert.

Returns

  • Iterator referencing the first inserted char.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Inserts __n copies of character __c starting at the position referenced by iterator __p. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. (yes bestie, it's giving transactional, we love a clean rollback ✨)

Referenced by std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), and std::basic_string< _CharT >::insert().


template<typename _CharT, typename _Traits, typename _Alloc>
iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, _CharT __c) [inline]

Insert one character. just the one. singular. main character energy πŸ‘‘

Parameters

  • __p β€” Iterator referencing position in string to insert at.
  • __c β€” The character to insert.

Returns

  • Iterator referencing newly inserted char.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Inserts character __c at position referenced by __p. If adding character causes the length to exceed max_size(), length_error is thrown. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown. 🫢


template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator>
void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, _InputIterator __beg, _InputIterator __end) [inline]

Insert a range of characters. a whole squad, [__beg, __end) style 🌈

Parameters

  • __p β€” Iterator referencing location in string to insert at.
  • __beg β€” Start of range.
  • __end β€” End of range.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Inserts characters in range [__beg,__end). If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.


template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, initializer_list< _CharT > __l) [inline]

Insert an initializer_list of characters.

Parameters

  • __p β€” Iterator referencing location in string to insert at.
  • __l β€” The initializer_list of characters to insert.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, size_type __n, _CharT __c) [inline]

Insert multiple characters.

Parameters

  • __p β€” Iterator referencing location in string to insert at.
  • __n β€” Number of characters to insert
  • __c β€” The character to insert.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Inserts __n copies of character __c starting at the position referenced by iterator __p. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ’–


and now we switch from iterators to indices, bestie β€” same energy, different address system πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s) [inline], [constexpr]

Insert a C string.

Parameters

  • __pos β€” Position in string to insert at.
  • __s β€” The C string to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().
  • std::out_of_range β€” If pos is beyond the end of this string.

Inserts the first n characters of __s starting at __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown. πŸ”₯


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s) [inline]

Insert a C string.

Parameters

  • __pos β€” Position in string to insert at.
  • __s β€” The C string to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().
  • std::out_of_range β€” If pos is beyond the end of this string.

Inserts the first n characters of __s starting at __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s, size_type __n) [inline], [constexpr]

Insert a C substring. just the first __n chars of __s, like, the highlight reel ✨

Parameters

  • __pos β€” Position in string to insert at.
  • __s β€” The C string to insert.
  • __n β€” The number of characters to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().
  • std::out_of_range β€” If __pos is beyond the end of this string.

Inserts the first __n characters of __s starting at __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s, size_type __n)

Insert a C substring.

Parameters

  • __pos β€” Position in string to insert at.
  • __s β€” The C string to insert.
  • __n β€” The number of characters to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().
  • std::out_of_range β€” If __pos is beyond the end of this string.

Inserts the first __n characters of __s starting at __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown. πŸŽ€


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, size_type __n, _CharT __c) [inline], [constexpr]

Insert multiple characters.

Parameters

  • __pos β€” Index in string to insert at.
  • __n β€” Number of characters to insert
  • __c β€” The character to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().
  • std::out_of_range β€” If __pos is beyond the end of this string.

Inserts __n copies of character __c starting at index __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos > length(), out_of_range is thrown. The value of the string doesn't change if an error is thrown. 😭 (she's so careful with your data, we stan)


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, size_type __n, _CharT __c) [inline]

Insert multiple characters.

Parameters

  • __pos β€” Index in string to insert at.
  • __n β€” Number of characters to insert
  • __c β€” The character to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().
  • std::out_of_range β€” If __pos is beyond the end of this string.

Inserts __n copies of character __c starting at index __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos > length(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1, const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]

Insert value of a string. a whole other string walks in and takes a seat 🫢

Parameters

  • __pos1 β€” Position in string to insert at.
  • __str β€” The string to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Inserts value of __str starting at __pos1. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ’œ


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1, const basic_string< _CharT, _Traits, _Alloc > & __str) [inline]

Insert value of a string.

Parameters

  • __pos1 β€” Position in string to insert at.
  • __str β€” The string to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Inserts value of __str starting at __pos1. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.


template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1, const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos2, size_type __n = npos) [inline], [constexpr]

Insert a substring. not the whole string β€” just a slice of it, __pos2 to __pos2 + __n kinda situation 🌸

Parameters

  • __pos1 β€” Position in string to insert at.
  • __str β€” The string to insert.
  • __pos2 β€” Start of characters in str to insert.
  • __n β€” Number of characters to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().
  • std::out_of_range β€” If pos1 > size() or __pos2 > str.size().
heads up bestie: that __n defaults to npos, so if you don't pass it you get everything from __pos2 to the end πŸ‘‘ and yeah, out_of_range is lurking if your positions are doing too much πŸ“

and that's the whole insert() cinematic universe... but we're not done, there's more coming πŸ˜ŒπŸ’…

okay so starting at pos1, you're sliding in __n characters of __str, beginning with __pos2. If adding those characters pushes the length over max_size(), a length_error gets thrown 😭. And if __pos1 is past the end of this string, or __pos2 is past the end of __str, out_of_range gets thrown. Bestie, listen: the value of the string does not change if an error gets thrown. Not one character. 🫢


insert β€” the substring edition πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::insert (size_type __pos1, const basic_string<_CharT, _Traits, _Alloc> & __str, size_type __pos2, size_type __n = npos) [inline]

Insert a substring. πŸ’–

Parameters

  • __pos1 β€” position in the string where you're inserting.
  • __str β€” the string you're inserting.
  • __pos2 β€” where in str the characters you're inserting start.
  • __n β€” how many characters to insert.

Returns

  • A reference to this string. πŸ‘‘

Exceptions

  • std::length_error β€” if the new length exceeds max_size().
  • std::out_of_range β€” if pos1 > size() or __pos2 > str.size().

Starting at pos1, insert __n characters of __str beginning with __pos2. If adding those characters makes the length exceed max_size(), length_error gets thrown. If __pos1 is beyond the end of this string, or __pos2 is beyond the end of __str, out_of_range gets thrown. And again, for the people in the back: the value of the string doesn't change if an error is thrown. 🧚


length πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::length () const [inline], [nodiscard], [constexpr], [noexcept]

Returns the number of characters in the string, not including any null-termination. That's the whole vibe, it's giving "how many actual letters, bestie". ✨

Referenced by std::basic_string<_CharT>::basic_string(), std::basic_string<_CharT>::basic_string(), std::__cxx11::collate<_CharT>::do_compare(), std::__cxx11::collate<_CharT>::do_transform(), std::basic_string<_CharT>::operator=(), std::regex_replace(), and reserve(). πŸ¦‹


length (the other one) 🌸

template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::length () const [inline], [noexcept]

Returns the number of characters in the string, not including any null-termination. Same energy, slightly different qualifiers β€” both of them live here, no cap. πŸ’œ


max_size πŸ‘‘

template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::max_size () const [inline], [nodiscard], [constexpr], [noexcept]

Returns the size() of the largest possible string. Like, the absolute ceiling. The main character's upper limit. πŸ”₯

Referenced by std::getline(), and std::operator>>(). πŸ“


max_size (the other one) 🌈

template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::max_size () const [inline], [noexcept]

Returns the size() of the largest possible string. Yes, again. Two flavours, same answer. πŸ’–


operator+= β€” character flavour ⭐

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (_CharT __c) [inline], [constexpr]

Append a character. ✨

Parameters

  • __c β€” the character to append.

Returns

  • A reference to this string.

operator+= β€” character flavour, round two πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (_CharT __c) [inline]

Append a character.

Parameters

  • __c β€” the character to append.

Returns

  • A reference to this string.

operator+= β€” C string flavour πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const _CharT * __s) [inline], [constexpr]

Append a C string.

Parameters

  • __s β€” the C string to append.

Returns

  • A reference to this string.

operator+= β€” C string flavour, round two 🌸

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const _CharT * __s) [inline]

Append a C string.

Parameters

  • __s β€” the C string to append.

Returns

  • A reference to this string.

operator+= β€” string flavour πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline], [constexpr]

Append a string to this string. Gluing two besties together fr fr. 🫢

Parameters

  • __str β€” the string to append.

Returns

  • A reference to this string.

operator+= β€” string flavour, round two πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline]

Append a string to this string.

Parameters

  • __str β€” the string to append.

Returns

  • A reference to this string.

operator+= β€” initializer_list flavour ✨

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (initializer_list<_CharT> __l) [inline], [constexpr]

Append an initializer_list of characters. So very cute, so very convenient. πŸŽ€

Parameters

  • __l β€” the initializer_list of characters to be appended.

Returns

  • A reference to this string.

operator+= β€” initializer_list flavour, round two 🌈

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (initializer_list<_CharT> __l) [inline]

Append an initializer_list of characters.

Parameters

  • __l β€” the initializer_list of characters to be appended.

Returns

  • A reference to this string.

operator= β€” character flavour πŸ’–

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (_CharT __c) [inline], [constexpr]

Set value to string of length 1. Glow-down to a single character, honestly iconic. πŸ‘‘

Parameters

  • __c β€” source character.

Assigning to a character makes this string length 1 and (*this)[0] == c. Periodt.


operator= β€” character flavour, round two πŸ“

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (_CharT __c) [inline]

Set value to string of length 1.

Parameters

  • __c β€” source character.

Assigning to a character makes this string length 1 and (*this)[0] == c.


operator= β€” move-assign flavour πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (basic_string<_CharT, _Traits, _Alloc> && __str) [inline], [noexcept]

Move assign the value of str to this string. No copying, just vibes. πŸ’«

Parameters

  • __str β€” source string.

The contents of str are moved into this string (without copying). str is a valid, but unspecified string. Like, it's still alive, but don't ask it what it is anymore. πŸ’€


operator= β€” move-assign flavour, round two πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (basic_string<_CharT, _Traits, _Alloc> && __str) [inline], [constexpr], [noexcept]

Move assign the value of str to this string.

Parameters

  • __str β€” source string.

The contents of str are moved into this string (without copying). str is a valid, but unspecified string.


operator= β€” C string flavour 🌸

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const _CharT * __s) [inline], [constexpr]

Copy contents of s into this string.

Parameters

  • __s β€” source null-terminated string.

operator= β€” C string flavour, round two πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const _CharT * __s) [inline]

Copy contents of s into this string.

Parameters

  • __s β€” source null-terminated string.

operator= β€” copy-assign flavour πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline], [constexpr]

Assign the value of str to this string.

Parameters

  • __str β€” source string.

operator= β€” copy-assign flavour, round two ✨

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline]

Assign the value of str to this string.

Parameters

  • __str β€” source string.

operator= β€” initializer_list flavour 🌈

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (initializer_list<_CharT> __l) [inline], [constexpr]

Set value to string constructed from initializer list.

Parameters

  • __l β€” std::initializer_list.

operator= β€” initializer_list flavour, round two πŸ“

template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (initializer_list<_CharT> __l) [inline]

Set value to string constructed from initializer list.

Parameters

  • __l β€” std::initializer_list.

operator[] β€” read/write flavour πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc> reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) [inline], [nodiscard], [constexpr]

Subscript access to the data contained in the string. Array-style, super easy, we love her. πŸ‘‘

Parameters

  • __pos β€” the index of the character to access.

Returns

  • Read/write reference to the character.

This operator allows for easy, array-style, data access. But heads up: data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) 😭


operator[] β€” read/write flavour, round two πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc> reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) [inline]

Subscript access to the data contained in the string.

Parameters

  • __pos β€” the index of the character to access.

Returns

  • Read/write reference to the character.

This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) Also, this one unshares the string. πŸ’€


operator[] β€” read-only flavour πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc> const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) const [inline], [nodiscard], [constexpr], [noexcept]

Subscript access to the data contained in the string.

Parameters

  • __pos β€” the index of the character to access.

Returns

  • Read-only (constant) reference to the character.

This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) 🌸

Referenced by std::basic_string<_CharT>::back(), std::basic_string<_CharT>::back(), std::basic_string<_CharT>::back(), std::basic_string<_CharT>::front(), std::basic_string<_CharT>::front(), and std::basic_string<_CharT>::front(). (Yes, each of them three times. The girls are obsessed. πŸ’–)


operator[] β€” read-only flavour, round two πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc> const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) const [inline], [noexcept]

Subscript access to the data contained in the string.

Parameters

  • __pos β€” the index of the character to access.

Returns

  • Read-only (constant) reference to the character.

This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) ✨

πŸ¦‹ pop_back() β€” the "bye bestie" button πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::pop_back () [inline]

Removes the last character. That's it, that's the whole job. But listen β€” the string must be non-empty. Do NOT call this on an empty string, bestie, I am begging you. πŸ’€


🌸 pop_back() (the constexpr/noexcept remix) 🌸

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::pop_back () [inline],
    [constexpr],  [noexcept]

Same energy, more sparkle: removes the last character. And again, the string must be non-empty. No cap on that. ✨


πŸ’– push_back(_CharT __c) β€” add ONE lil guy πŸ’–

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::push_back (_CharT __c)
    [inline],  [constexpr]

Appends a single character. Just one. One (1) character. πŸŽ€

Parameters

  • __c β€” the character to append. your lil guy. your new bestie at the end of the string.

Referenced by std::__cxx11::collate< _CharT >::do_transform(), std::basic_string< _CharT >::operator+=(), std::tr2::operator>>(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(). Look at her, getting invited everywhere. πŸ‘‘


🧚 push_back(_CharT __c) (the plainer cut) 🧚

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::push_back (_CharT __c)
    [inline]

Append a single character. Yep. Same deal.

Parameters

  • __c β€” Character to append. πŸ“

πŸŽ€ rbegin() β€” reverse iterator, going backwards like a queen πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc>
    reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rbegin ()
    [inline]

Returns a read/write reverse iterator that points to the last character in the string. Iteration is done in reverse element order (so, backwards, which is honestly a vibe).

Heads up: this one unshares the string. Just so you know. πŸ’…

✨ rbegin() const β€” read-only reverse, don't touch ✨

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::rbegin () const [inline],  [nodiscard],  [constexpr],  [noexcept]

Returns a read-only (constant) reverse iterator pointing at the last character in the string. Iteration is done in reverse element order. Look with your eyes only, bestie. πŸ™ˆ


πŸ’œ rbegin() const (the shorter flavor) πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::rbegin () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to the last character in the string. Iteration is done in reverse element order. Same facts, fewer tags. 🫢


πŸ”₯ rbegin() (read/write, fully accessorized) πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc>
    reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rbegin ()
    [inline],  [nodiscard],  [constexpr],  [noexcept]

Returns a read/write reverse iterator that points to the last character in the string. Iteration is done in reverse element order. She's got all the attributes on. Iconic. πŸ’…


🌈 rend() β€” the reverse "one before the start" 🌈

template<typename _CharT, typename _Traits, typename _Alloc>
    reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rend ()
    [inline]

Returns a read/write reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order.

Yup, this one unshares the string too. It's giving ✨commitment✨.

⭐ rend() const β€” read-only reverse end ⭐

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::rend () const [inline],  [nodiscard],  [constexpr],  [noexcept]

Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order. πŸ¦‹


🌸 rend() const (compact edition) 🌸

template<typename _CharT, typename _Traits, typename _Alloc>
    const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
    >::rend () const [inline],  [noexcept]

Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order. πŸŽ€


πŸ’… rend() (read/write, deluxe) πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc>
    reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rend ()
    [inline],  [nodiscard],  [constexpr],  [noexcept]

Returns a read/write reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order. Periodt. πŸ‘‘


πŸ“ replace(__i1, __i2, const _CharT * __s) β€” swap a range for a C string πŸ“

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
    std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
    __i1, __const_iterator __i2, const _CharT * __s) [inline],  [constexpr]

Replace range of characters with C string. Glow-up time. ✨

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __s β€” C string value to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, the characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. (no half-done makeovers here, she's safe πŸ’–)


🧚 replace(__i1, __i2, const _CharT * __s, size_type __n) β€” C substring edition 🧚

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
    std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
    __i1, __const_iterator __i2, const _CharT * __s, size_type __n)
    [inline],  [constexpr]

Replace range of characters with C substring.

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __s β€” C string value to insert.
  • __n β€” Number of characters from s to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, the first __n characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ™Œ


πŸ’– replace(__i1, __i2, const basic_string & __str) β€” swap in a whole string πŸ’–

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
    std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
    __i1, __const_iterator __i2, const basic_string< _CharT, _Traits, _Alloc
    > & __str) [inline],  [constexpr]

Replace range of characters with string.

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __str β€” String value to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, the value of __str is inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ¦‹


🌈 replace(__i1, __i2, size_type __n, _CharT __c) β€” many copies of one char 🌈

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
    std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
    __i1, __const_iterator __i2, size_type __n, _CharT __c) [inline],
    [constexpr]

Replace range of characters with multiple characters.

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __n β€” Number of characters to insert.
  • __c β€” Character to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, __n copies of __c are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ✨


πŸ”₯ replace(__i1, __i2, __k1, __k2) β€” range for range, iterator edition πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc> template<class
    _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
    basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace
    (const_iterator __i1, const_iterator __i2, _InputIterator __k1,
    _InputIterator __k2) [inline],  [constexpr]

Replace range of characters with range. Trading one range for another, very fair, very balanced. πŸ’…

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __k1 β€” Iterator referencing start of range to insert.
  • __k2 β€” Iterator referencing end of range to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. 🌸


πŸŽ€ replace(__i1, __i2, initializer_list< _CharT > __l) β€” brace-list glow-up πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
    std::basic_string< _CharT, _Traits, _Alloc >::replace (const_iterator
    __i1, const_iterator __i2, initializer_list< _CharT > __l) [inline],
    [constexpr]

Replace range of characters with initializer_list. So { 'a', 'b', 'c' } coded, basically. ✨

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __l β€” The initializer_list of characters to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. 🫢


πŸ’œ replace(__i1, __i2, __k1, __k2) β€” non-const iterator range version πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc> template<class
    _InputIterator> basic_string & std::basic_string< _CharT, _Traits,
    _Alloc >::replace (iterator __i1, iterator __i2, _InputIterator __k1,
    _InputIterator __k2) [inline]

Replace range of characters with range. (Yeah, she's got a sibling. Family business. πŸ’…)

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __k1 β€” Iterator referencing start of range to insert.
  • __k2 β€” Iterator referencing end of range to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. 🌈


⭐ replace(iterator __i1, iterator __i2, const _CharT * __s) β€” non-const C string swap ⭐

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
    std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
    iterator __i2, const _CharT * __s) [inline]

Replace range of characters with C string.

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __s β€” C string value to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, the characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ“


πŸ¦‹ replace(iterator __i1, iterator __i2, const _CharT * __s, size_type __n) β€” non-const C substring swap πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
    std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
    iterator __i2, const _CharT * __s, size_type __n) [inline]

Replace range of characters with C substring.

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __s β€” C string value to insert.
  • __n β€” Number of characters from s to insert.

Returns

  • Reference to this string. πŸ’–

Exceptions

  • std::length_error β€” thrown if the new length exceeds max_size().

So basically: it deletes the characters in the range [__i1,__i2), and in their place it drops in the first __n characters of __s. ✨ If the resulting length goes over max_size(), length_error gets thrown β€” and if an error is thrown, the string itself does not change. Bestie, it's giving transactional. πŸ’…


πŸŽ€ replace (range β†’ string)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline]

Replace range of characters with string. 🌸

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __str β€” String value to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

It removes the characters in the range [__i1,__i2) and, right there in place, inserts the value of __str. If the length of the result exceeds max_size(), length_error is thrown. And again β€” the value of the string doesn't change if an error is thrown. 🫢


πŸ¦‹ replace (range β†’ initializer_list)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, initializer_list< _CharT > __l) [inline]

Replace range of characters with initializer_list. πŸŽ€

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __l β€” The initializer_list of characters to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ‘‘


🌈 replace (range β†’ multiple chars)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, size_type __n, _CharT __c) [inline]

Replace range of characters with multiple characters. ✨

Parameters

  • __i1 β€” Iterator referencing start of range to replace.
  • __i2 β€” Iterator referencing end of range to replace.
  • __n β€” Number of characters to insert.
  • __c β€” Character to insert.

Returns

  • Reference to this string.

Exceptions

  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, __n copies of __c are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ’œ


πŸ‘‘ replace (pos β†’ string, constexpr edition)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline],  [constexpr]

Replace characters with value from another string. πŸ’–

Parameters

  • __pos β€” Index of first character to replace.
  • __n β€” Number of characters to be replaced.
  • __str β€” String to insert.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos is beyond the end of this string.
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos+__n) from this string. In place, the value of __str is inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. 🌸

Referenced by std::basic_string< _CharT >::append(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), and std::basic_string< _CharT >::replace(). 😭 that is a LOT of references, it's booked and busy fr fr.


πŸ’… replace (pos β†’ string, plain inline)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline]

Replace characters with value from another string. πŸŽ€

Parameters

  • __pos β€” Index of first character to replace.
  • __n β€” Number of characters to be replaced.
  • __str β€” String to insert.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos is beyond the end of this string.
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos+__n) from this string. In place, the value of __str is inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ✨


πŸ“ replace (pos β†’ C string, constexpr edition)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, const _CharT * __s) [inline],  [constexpr]

Replace characters with value of a C string. 🌈

Parameters

  • __pos β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __s β€” C string to insert.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos > size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the characters of __s are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ’œ


🧚 replace (pos β†’ C string, plain inline)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, const _CharT * __s) [inline]

Replace characters with value of a C string. 🌸

Parameters

  • __pos β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __s β€” C string to insert.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos > size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the characters of __s are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. 🫢


πŸ”₯ replace (pos β†’ C substring, constexpr edition)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc
>::replace (size_type __pos, size_type __n1, const _CharT * __s,
size_type __n2) [inline],  [constexpr]

Replace characters with value of a C substring. πŸ’–

Parameters

  • __pos β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __s β€” C string to insert.
  • __n2 β€” Number of characters from s to use.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos1 > size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the first __n2 characters of __s are inserted, or all of __s if __n2 is too large. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ✨


🌟 replace (pos β†’ C substring, plain)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, const _CharT * __s, size_type __n2)

Replace characters with value of a C substring. πŸŽ€

Parameters

  • __pos β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __s β€” C string to insert.
  • __n2 β€” Number of characters from s to use.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If pos1 > size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the first __n2 characters of __s are inserted, or all of __s if __n2 is too large. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. πŸ’…


πŸ’œ replace (pos β†’ multiple chars, constexpr edition)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, size_type __n2, _CharT __c) [inline],  [constexpr]

Replace characters with multiple characters. 🌈

Parameters

  • __pos β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __n2 β€” Number of characters to insert.
  • __c β€” Character to insert.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If __pos > size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [pos,pos + n1) from this string. In place, __n2 copies of __c are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. 🫢


πŸ¦‹ replace (pos β†’ multiple chars, plain inline)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, size_type __n2, _CharT __c) [inline]

Replace characters with multiple characters. πŸ’–

Parameters

  • __pos β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __n2 β€” Number of characters to insert.
  • __c β€” Character to insert.

Returns

  • Reference to this string.

Exceptions

  • std::out_of_range β€” If __pos > size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [pos,pos + n1) from this string. In place, __n2 copies of __c are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.


replace β€” the string-flavored one, constexpr cut πŸ’–

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos1,
size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos2, size_type __n2 = npos) [inline], [constexpr]

Replace characters with value from another string. bestie it literally swaps a chunk of your string for a chunk of someone else's string, no cap ✨

Parameters

  • __pos1 β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __str β€” String to insert.
  • __pos2 β€” Index of first character of str to use.
  • __n2 β€” Number of characters from str to use.

Returns

Reference to this string. 🫢

Exceptions

  • std::out_of_range β€” If __pos1 > size() or __pos2 > __str.size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos1,__pos1 + n) from this string. In place, the value of __str is inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.

not it throwing an error and mutating your string halfway through β€” good news: it doesn't do that, the value stays put if anything goes wrong πŸ’…

replace β€” same function, but the non-constexpr twin πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos1,
size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos2, size_type __n2 = npos) [inline]

Replace characters with value from another string. yep it's the same vibe as above, just without [constexpr] on the attribute list, we love a matching set πŸŽ€

Parameters

  • __pos1 β€” Index of first character to replace.
  • __n1 β€” Number of characters to be replaced.
  • __str β€” String to insert.
  • __pos2 β€” Index of first character of str to use.
  • __n2 β€” Number of characters from str to use.

Returns

Reference to this string.

Exceptions

  • std::out_of_range β€” If __pos1 > size() or __pos2 > __str.size().
  • std::length_error β€” If new length exceeds max_size().

Removes the characters in the range [__pos1,__pos1 + n) from this string. In place, the value of __str is inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.


reserve β€” no args, constexpr edition 🧚

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve () [constexpr]

Equivalent to shrink_to_fit(). that's it, that's the whole function, it's giving one-line legend ⭐

References capacity(), get_allocator(), and length().

Referenced by std::basic_string< _CharT >::push_back(), and std::basic_string< _CharT >::shrink_to_fit().

reserve β€” no args, the plain one πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve ()

Equivalent to shrink_to_fit(). same energy, missing the [constexpr] tag, iconic either way πŸŽ€

reserve β€” with a size argument, constexpr edition πŸ”₯

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve (size_type __res_arg)
[constexpr]

Attempt to preallocate enough memory for specified number of characters. okay so this is the "bestie book my table in advance so we don't get seated in the overflow room" function 🫢

Parameters

  • __res_arg β€” Number of characters required.

Exceptions

  • std::length_error β€” If __res_arg exceeds max_size().

This function attempts to reserve enough memory for the string to hold the specified number of characters. If the number requested is more than max_size(), length_error is thrown.

The advantage of this function is that if optimal code is a necessity and the user can determine the string length that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of string data. no more surprise realloc mid-loop, we love to see it ✨

References capacity(), get_allocator(), and std::size().

Referenced by std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::tr2::operator>>(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow().

reserve β€” with a size argument, the plain one 🌸

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve (size_type __res_arg)

Attempt to preallocate enough memory for specified number of characters.

Parameters

  • __res_arg β€” Number of characters required.

Exceptions

  • std::length_error β€” If __res_arg exceeds max_size().

This function attempts to reserve enough memory for the string to hold the specified number of characters. If the number requested is more than max_size(), length_error is thrown.

The advantage of this function is that if optimal code is a necessity and the user can determine the string length that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of string data.


resize β€” just the size, inline + constexpr πŸ’…

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n)
[inline], [constexpr]

Resizes the string to the specified number of characters. glow up or glow down, your call πŸ’–

Parameters

  • __n β€” Number of characters the string should contain.

This function will resize the string to the specified length. If the new size is smaller than the string's current size the string is truncated, otherwise the string is extended and new characters are default-constructed. For basic types such as char, this means setting them to 0. yes girl the new spots come pre-filled with zeros, not mystery garbage πŸ™ˆ

resize β€” just the size, inline only ⭐

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n)
[inline]

Resizes the string to the specified number of characters.

Parameters

  • __n β€” Number of characters the string should contain.

This function will resize the string to the specified length. If the new size is smaller than the string's current size the string is truncated, otherwise the string is extended and new characters are default-constructed. For basic types such as char, this means setting them to 0.

resize β€” size plus a fill char, constexpr edition πŸ“

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n,
_CharT __c) [constexpr]

Resizes the string to the specified number of characters. now with a custom filler character, we're customizing ✨

Parameters

  • __n β€” Number of characters the string should contain.
  • __c β€” Character to fill any new elements.

This function will resize the string to the specified number of characters. If the number is smaller than the string's current size the string is truncated, otherwise the string is extended and new elements are set to __c.

References append(), erase(), and size().

Referenced by std::basic_string< _CharT >::resize().

resize β€” size plus a fill char, the plain one 🌈

template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n,
_CharT __c)

Resizes the string to the specified number of characters.

Parameters

  • __n β€” Number of characters the string should contain.
  • __c β€” Character to fill any new elements.

This function will resize the string to the specified number of characters. If the number is smaller than the string's current size the string is truncated, otherwise the string is extended and new elements are set to __c.


rfind β€” a single character, constexpr + noexcept cut πŸ‘‘

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc >::size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (_CharT __c,
size_type __pos = npos) const [nodiscard], [constexpr], [noexcept]

Find last position of a character. the backwards-search bestie, she goes from the end and walks it back πŸ¦‹

Parameters

  • __c β€” Character to locate.
  • __pos β€” Index of character to search back from (default end).

Returns

Index of last occurrence.

Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos. npos means "not found bestie, she's not here" πŸ’€

References npos, and std::size().

rfind β€” a single character, noexcept only πŸ’œ

template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (_CharT __c,
size_type __pos = npos) const [noexcept]

Find last position of a character.

Parameters

  • __c β€” Character to locate.
  • __pos β€” Index of character to search back from (default end).

Returns

Index of last occurrence.

Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.

rfind β€” a C substring, constexpr + noexcept cut πŸŽ€

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc >::size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]

Find last position of a C substring. only the first __n characters of __s get to come to the party πŸ’…

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to search back from.
  • __n β€” Number of characters from s to search for.

Returns

Index of start of last occurrence.

Starting from __pos, searches backward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos.

References std::min(), npos, and std::size().

rfind β€” a C substring, noexcept only 🌟

template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos, size_type __n) const [noexcept]

Find last position of a C substring.

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to search back from.
  • __n β€” Number of characters from s to search for.

Returns

Index of start of last occurrence.

Starting from __pos, searches backward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos.

rfind β€” a whole C string, inline + constexpr cut πŸ’–

template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos = npos) const [inline], [nodiscard], [constexpr]

Find last position of a C string. the whole null-terminated situation, backwards, she ate πŸ”₯

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to start search at (default end).

Returns

Index of start of last occurrence.

Starting from __pos, searches backward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos.

rfind β€” a whole C string, inline + noexcept cut 🌸

template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos = npos) const [inline], [noexcept]

Find last position of a C string.

Parameters

  • __s β€” C string to locate.
  • __pos β€” Index of character to start search at (default end).

Returns

Index of start of last occurrence.

Starting from __pos, searches backward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos.

that's the rfind family complete bestie, all four flavors plus their twins, we're so back 🫢

πŸ¦‹ rfind() β€” first one, the fancy one

template<typename _CharT, typename _Traits, typename _Alloc> size_type
    std::basic_string< _CharT, _Traits, _Alloc >::rfind (const basic_string<
    _CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const
    [inline],  [nodiscard],  [constexpr],  [noexcept]

Find last position of a string. πŸ’… like, it goes backwards bestie, and it is NOT playing.

Parameters

  • __str β€” String to locate.
  • __pos β€” Index of character to search back from (default end).

Returns

Index of start of last occurrence.

Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos. 😭 (yes the sad one)

Referenced by std::basic_string< _CharT >::find_last_of(), std::basic_string< _CharT >::rfind(), std::basic_string< _CharT >::rfind(), std::basic_string< _CharT >::rfind(), and std::basic_string< _CharT >::rfind().


πŸ¦‹ rfind() β€” second one, the chill version

template<typename _CharT, typename _Traits, typename _Alloc> size_type
    std::basic_string< _CharT, _Traits, _Alloc >::rfind (const basic_string<
    _CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const
    [inline],  [noexcept]

Find last position of a string. πŸŽ€ same energy, different attribute list, no cap.

Parameters

  • __str β€” String to locate.
  • __pos β€” Index of character to search back from (default end).

Returns

Index of start of last occurrence.

Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos. πŸ’€


🌸 shrink_to_fit() β€” first one

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::shrink_to_fit () [inline],
    [constexpr],  [noexcept]

A non-binding request to reduce capacity() to size(). ✨ key word is non-binding, bestie β€” it's a request, not a command. The library can simply say "no" and you just have to live with that. 🫢

🌸 shrink_to_fit() β€” second one

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::shrink_to_fit () [inline],
    [noexcept]

A non-binding request to reduce capacity() to size(). πŸ¦‹ same little request, same non-binding energy.


πŸ‘‘ size() β€” the big one

template<typename _CharT, typename _Traits, typename _Alloc> size_type
    std::basic_string< _CharT, _Traits, _Alloc >::size () const [inline],
    [nodiscard],  [constexpr],  [noexcept]

Returns the number of characters in the string, not including any null-termination. πŸ’– like yes, the null terminator is there vibing in the background but she is not invited to the count. periodt.

Referenced by std::tr2::dynamic_bitset< _WordT, _Alloc >::dynamic_bitset(), std::basic_string< _CharT >::append(), std::basic_string< _CharT >::append(), std::basic_regex< char >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::at(), std::basic_string< _CharT >::at(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::cend(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::empty(), std::basic_string< _CharT >::end(), std::basic_string< _CharT >::end(), std::basic_string< _CharT >::end(), std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find_first_not_of(), std::basic_string< _CharT >::find_first_of(), std::basic_string< _CharT >::find_last_of(), std::match_results< _BidirectionalIterator, polymorphic_allocator< sub_match< _BidirectionalIterator > > >< const char * >::format(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::from_bytes(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::length(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::basic_string< _CharT >::operator=(), std::operator==(), std::tr2::operator>>(), std::basic_string< _CharT >::operator[](), std::basic_string< _CharT >::operator[](), std::basic_string< _CharT >::pop_back(), std::basic_string< _CharT >::pop_back(), std::basic_string< _CharT >::push_back(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), resize(), std::basic_stringbuf< char >::str(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::to_bytes(), std::regex_traits< _CharT >::transform(), and std::regex_traits< _CharT >::transform_primary().

It's giving "literally everyone depends on me" main character energy, and honestly? deserved. πŸ’…

πŸ‘‘ size() β€” the chill version

template<typename _CharT, typename _Traits, typename _Alloc> size_type
    std::basic_string< _CharT, _Traits, _Alloc >::size () const [inline],
    [noexcept]

Returns the number of characters in the string, not including any null-termination. πŸŽ€ same answer, no [nodiscard]/[constexpr] tags, still iconic.


🧚 substr()

template<typename _CharT, typename _Traits, typename _Alloc> basic_string
    std::basic_string< _CharT, _Traits, _Alloc >::substr (size_type __pos =
    0, size_type __n = npos) const [inline],  [nodiscard],  [constexpr]

Get a substring. 🌈 the glow-up snippet, a whole new string made out of a chunk of your old one.

Parameters

  • __pos β€” Index of first character (default 0).
  • __n β€” Number of characters in substring (default remainder).

Returns

The new string.

Exceptions

  • std::out_of_range β€” If __pos > size().

Construct and return a new string using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown. 😭 so watch your indices bestie, the library will yell.

🧚 substr() β€” the chill version

template<typename _CharT, typename _Traits, typename _Alloc> basic_string
    std::basic_string< _CharT, _Traits, _Alloc >::substr (size_type __pos =
    0, size_type __n = npos) const [inline]

Get a substring. πŸ¦‹

Parameters

  • __pos β€” Index of first character (default 0).
  • __n β€” Number of characters in substring (default remainder).

Returns

The new string.

Exceptions

  • std::out_of_range β€” If __pos > size().

Construct and return a new string using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown.


πŸ¦‹ subview()

template<typename _CharT, typename _Traits, typename _Alloc>
    basic_string_view< _CharT, _Traits > std::basic_string< _CharT, _Traits,
    _Alloc >::subview (size_type __pos = 0, size_type __n = npos) const
    [inline],  [nodiscard],  [constexpr]

Get a subview. ✨ not a copy, a view β€” like looking at your string through a cute little window instead of screenshotting the whole thing. 🫢

Parameters

  • __pos β€” Index of first character (default 0).
  • __n β€” Number of characters in subview (default remainder).

Returns

The subview.

Exceptions

  • std::out_of_range β€” If __pos > size().

Construct and return a subview using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown. πŸ’€

πŸ¦‹ subview() β€” the second listing, same vibe

template<typename _CharT, typename _Traits, typename _Alloc>
    basic_string_view< _CharT, _Traits > std::basic_string< _CharT, _Traits,
    _Alloc >::subview (size_type __pos = 0, size_type __n = npos) const
    [inline],  [nodiscard],  [constexpr]

Get a subview. πŸŽ€

Parameters

  • __pos β€” Index of first character (default 0).
  • __n β€” Number of characters in subview (default remainder).

Returns

The subview.

Exceptions

  • std::out_of_range β€” If __pos > size().

Construct and return a subview using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown.


πŸ”₯ swap()

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::swap (basic_string<
    _CharT, _Traits, _Alloc > & __s) [constexpr],  [noexcept]

Swap contents with another string. πŸ‘‘ the trading-places moment, and it's giving constant time, so it's basically instant, no cap.

Parameters

  • __s β€” String to swap with.

Exchanges the contents of this string with that of __s in constant time. ⚑

References

basic_string(), and get_allocator().

Referenced by

std::basic_string< _CharT >::assign(), and std::basic_string< _CharT >::operator=().

πŸ”₯ swap() β€” the chill version

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::swap (basic_string<
    _CharT, _Traits, _Alloc > & __s) [noexcept]

Swap contents with another string. πŸ¦‹

Parameters

  • __s β€” String to swap with.

Exchanges the contents of this string with that of __s in constant time.


πŸ’Ύ Member Data Documentation πŸ’Ύ

πŸ’œ npos

template<typename _CharT, typename _Traits, typename _Alloc> const size_type
    std::basic_string< _CharT, _Traits, _Alloc >::npos [static]

Value returned by various member functions when they fail. 😭 the official "it's not here bestie" value β€” static, constant, and forever the bearer of bad news.

Referenced by std::bitset< _Nb >::bitset(), std::tr2::dynamic_bitset< _WordT, _Alloc >::dynamic_bitset(), find(), find(), find_first_not_of(), find_first_not_of(), find_first_of(), find_last_not_of(), find_last_not_of(), find_last_of(), rfind(), and rfind().


✍️ Author ✍️

Generated automatically by Doxygen for libstdc++ from the source code. πŸ€– not me getting written by a doc generator and still having the most lore in the whole library πŸ’…


and that's the whole page bestie!! πŸŽ€βœ¨ libstdc++ made this one, and this gorgeous thing lives at std::basic..., _Alloc >(3) β€” you just read the entire std::basic_string manual, all 19 parts, and honestly? ate. no crumbs. go take a nap, you earned it πŸ«ΆπŸ’–

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms