__GNU_DEBUG::BASIC_STRING(3)

πŸ’– __gnu_debug::basic_string< _CharT, _Traits, _Allocator >(3) πŸ’–

okay so this page is from the Library Functions Manual, and it's giving very specific debug-string energy. bestie, we're talking about a whole class here, so let's get into it. 🫢


✨ NAME ✨

__gnu_debug::basic_string< _CharT, _Traits, _Allocator > β€” Class std::basic_string with safety/checking/debug instrumentation. literally that's the whole name, no cap. πŸ’…


🌸 SYNOPSIS 🌸

first things first, you gotta pull it in like this:

#include <string>

and bestie, it inherits from __gnu_debug::_Safe_container< _SafeContainer, _Alloc, _SafeBase, _IsCxx11AllocatorAware >, and from std::basic_string< _CharT, _Traits, _Alloc >. periodt. πŸ’–

πŸ‘‘ Public Types πŸ‘‘

the type lineup is iconic, fr fr. every single one, exactly as written:

typedef _Allocator allocator_type
typedef __gnu_debug::_Safe_iterator< typename _Base::const_iterator, basic_string > const_iterator
typedef _Base::const_pointer const_pointer
typedef _Base::const_reference const_reference
typedef std::reverse_iterator< const_iterator > const_reverse_iterator
typedef _Base::difference_type difference_type
typedef __gnu_debug::_Safe_iterator< typename _Base::iterator, basic_string > iterator
typedef _Base::pointer pointer
typedef _Base::reference reference
typedef std::reverse_iterator< iterator > reverse_iterator
typedef _Base::size_type size_type
typedef _Traits traits_type
typedef _Traits::char_type value_type

no skips, no shortcuts, all the typedefs are present and accounted for. πŸ¦‹βœ¨

✨ Public Member Functions ✨

okay bestie buckle UP πŸŽ€ this is the whole member-function roster of basic_string and it is long, so grab a strawberry matcha and let's go. Every single overload is listed, no cap. 🫢

  • basic_string (_Base &&__base) noexcept β€” moves a _Base in, no throwing allowed, she's calm πŸ’…
  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> basic_string (_InputIterator __begin, _InputIterator __end, const _Allocator &__a=_Allocator()) β€” builds from an iterator range, and that _RequireInputIter is basically a bouncer checking ur iterators are legit ✨
  • basic_string (basic_string &&)=default β€” move constructor, defaulted, iconic πŸ‘‘
  • basic_string (basic_string &&__s, const _Allocator &__a) noexcept(std::is_nothrow_constructible< _Base, _Base, const _Allocator & >::value) β€” move + allocator, and it only promises noexcept if the base says it can πŸ¦‹
  • basic_string (const _Allocator &__a) noexcept β€” allocator-only ctor, empty string energy, no throw πŸ’œ
  • basic_string (const _Base &__base) β€” copies a _Base in 🌸
  • basic_string (const _CharT *__s, const _Allocator &__a=_Allocator()) β€” from a C string, allocator optional πŸŽ€
  • basic_string (const _CharT *__s, size_type __n, const _Allocator &__a=_Allocator()) β€” from a C string but only __n of it, precise queen πŸ’…
  • basic_string (const basic_string &)=default β€” copy constructor, defaulted, the classic 😌
  • basic_string (const basic_string &__s, const _Allocator &__a) β€” copy but swap in ur own allocator 🌈
  • basic_string (const basic_string &__str, size_type __pos, size_type __n=_Base::npos, const _Allocator &__a=_Allocator()) β€” copy a slice of another string starting at __pos ⭐
  • basic_string (size_type __n, _CharT __c, const _Allocator &__a=_Allocator()) β€” __n copies of character __c, the filler arc πŸ“
  • basic_string (std::initializer_list< _CharT > __l, const _Allocator &__a=_Allocator()) β€” straight from an initializer_list, curly-brace girlies rise πŸ’–
  • 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. 🧚
  • template<typename _Operation> void __resize_and_overwrite (size_type __n, _Operation __op) β€” Non-standard version of resize_and_overwrite for C++11 and above. yes there are two of them, don't @ me 😭

  • const _Base & _M_base () const noexcept β€” hands u the underlying base, const edition πŸ”’
  • _Base & _M_base () noexcept β€” same but non-const, go wild 😌
  • template<typename _InputIterator> basic_string< _CharT, _Traits, _Alloc > & _M_replace_dispatch (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2, __false_type) β€” internal dispatch machinery for the replace family, __false_type tagging along for the ride βš™οΈ
  • template<typename _InIterator> _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, forward_iterator_tag) β€” internal construction helper that knows it's got a forward_iterator_tag πŸ’«

  • template<typename _InputIterator> basic_string & append (_InputIterator __first, _InputIterator __last) β€” appends an iterator range 🌸
  • basic_string & append (const _CharT *__s) β€” appends a C string πŸŽ€
  • basic_string & append (const _CharT *__s, size_type __n) β€” appends __n chars of a C string πŸ’œ
  • basic_string & append (const basic_string &__str) β€” appends another string, the og move πŸ‘‘
  • basic_string & append (const basic_string &__str, size_type __pos, size_type __n) β€” appends a slice of another string πŸ¦‹
  • basic_string & append (size_type __n, _CharT __c) β€” appends __n copies of a char ✨
  • constexpr basic_string & append (const _CharT *__s, size_type __n) β€” Append a C substring. πŸ”₯
  • constexpr basic_string & append (const basic_string &__str) β€” Append a string to this string. πŸ’–
  • constexpr basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos) β€” Append a substring. 🌈
  • constexpr basic_string & append (initializer_list< _CharT > __l) β€” Append an initializer_list of characters. πŸ“
  • constexpr basic_string & append (size_type __n, _CharT __c) β€” Append multiple characters. ⭐

  • template<typename _InputIterator> basic_string & assign (_InputIterator __first, _InputIterator __last) β€” replaces contents with an iterator range πŸ”„
  • basic_string & assign (basic_string &&__x) noexcept(noexcept(std::declval< _Base & >().assign(std::move(__x)))) β€” move-assign, and the noexcept is literally mirroring whatever the base does πŸ’…
  • basic_string & assign (const _CharT *__s) β€” assign from a C string πŸŽ€
  • basic_string & assign (const _CharT *__s, size_type __n) β€” assign from __n chars of a C string 🌸
  • basic_string & assign (const basic_string &__str, size_type __pos, size_type __n) β€” assign from a slice of another string πŸ¦‹
  • basic_string & assign (const basic_string &__x) β€” assign from another string πŸ’œ
  • basic_string & assign (size_type __n, _CharT __c) β€” assign __n copies of a char ✨
  • basic_string & assign (std::initializer_list< _CharT > __l) β€” assign from an initializer_list 🌈
  • constexpr basic_string & assign (basic_string &&__str) noexcept(_Alloc_traits::_S_nothrow_move()) β€” Set value to contents of another string. πŸ‘‘
  • constexpr basic_string & assign (const _CharT *__s, size_type __n) β€” Set value to a C substring. πŸ“
  • constexpr basic_string & assign (const basic_string &__str) β€” Set value to contents of another string. πŸ’–
  • constexpr basic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos) β€” Set value to a substring of a string. πŸŽ€
  • constexpr basic_string & assign (size_type __n, _CharT __c) β€” Set value to multiple characters. ⭐

  • constexpr reference at (size_type __n) β€” Provides access to the data contained in the string. πŸ”
  • reference at (size_type __n) β€” Provides access to the data contained in the string. (again! different overload bestie) πŸ’…
  • constexpr const_reference at (size_type __n) const β€” Provides access to the data contained in the string. πŸ”’
  • const_reference at (size_type __n) const β€” Provides access to the data contained in the string. πŸ’œ
  • constexpr reference at (size_type __n) β€” Provides access to the data contained in the string. 🌸
  • constexpr const_reference at (size_type __n) const β€” Provides access to the data contained in the string. πŸ¦‹

  • constexpr const_reference back () const noexcept β€” last character, but read-only and unbothered 😌
  • constexpr reference back () noexcept β€” last character, editable πŸŽ€
  • iterator begin () β€” iterator to the front, no throw guarantee, she's just vibing ✨
  • const_iterator begin () const noexcept β€” const iterator to the front πŸ”’
  • const _CharT * c_str () const noexcept β€” null-terminated C string pointer, the classic 🫢
  • constexpr size_type capacity () const noexcept β€” how much she can hold before reallocating πŸ’ͺ
  • const_iterator cbegin () const noexcept β€” const begin, the c-prefix girlies get it 🌈
  • const_iterator cend () const noexcept β€” const end, matching set πŸŽ€
  • void clear () β€” wipe it, bye πŸ‘‹
  • constexpr int compare (const _CharT *__s) const noexcept β€” compare against a C string, no throw πŸ’…
  • constexpr int compare (const basic_string &__str) const β€” Compare to a string. πŸ¦‹
  • constexpr int compare (size_type __pos, size_type __n, const basic_string &__str) const β€” Compare substring to a string. 🌸
  • int compare (size_type __pos, size_type __n, const basic_string &__str) const β€” Compare substring to a string. πŸ’œ
  • constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s) const β€” Compare substring to a C string. πŸŽ€
  • constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const β€” Compare substring against a character array. ⭐
  • int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const β€” Compare substring against a character array. πŸ”₯
  • constexpr int compare (size_type __pos1, size_type __n1, const _CharT *__s) const β€” compare a chunk of urself to a C string ✨
  • constexpr int compare (size_type __pos1, size_type __n1, const _CharT *__s, size_type __n2) const β€” same but u cap the C string at __n2 πŸ“
  • 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. 🌈
  • 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. πŸ‘‘
  • constexpr int compare (size_type __pos, size_type __n, const basic_string &__str) const β€” Compare substring to a string. πŸ’–
  • constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s) const β€” Compare substring to a C string. πŸŽ€
  • constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const β€” Compare substring against a character array. πŸ¦‹
  • 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. πŸ’œ

  • constexpr bool contains (_CharT __x) const noexcept β€” does she contain char __x? yes/no, no throw πŸ”
  • bool contains (_CharT __x) const noexcept β€” same question, other overload πŸ’…
  • constexpr bool contains (basic_string_view< _CharT, _Traits > __x) const noexcept β€” contains that string view? 🌸
  • bool contains (basic_string_view< _CharT, _Traits > __x) const noexcept β€” contains that string view? (again) πŸ¦‹
  • constexpr bool contains (const _CharT *__x) const noexcept β€” contains that C string? πŸŽ€
  • bool contains (const _CharT *__x) const noexcept β€” contains that C string? (again) ✨
  • size_type copy (_CharT *__s, size_type __n, size_type __pos=0) const β€” copies out into ur buffer, no null terminator added, careful bestie πŸ™ˆ
  • constexpr size_type copy (_CharT *__s, size_type __n, size_type __pos=0) const β€” Copy substring into C string. πŸ“
  • const_reverse_iterator crbegin () const noexcept β€” const reverse begin, going backwards in style 🌈
  • const_reverse_iterator crend () const noexcept β€” const reverse end πŸŽ€
  • const _CharT * data () const noexcept β€” read-only pointer to the contents πŸ’œ
  • constexpr _CharT * data () noexcept β€” Return non-const pointer to contents. πŸ”₯
  • constexpr bool empty () const noexcept β€” is she empty? 😭
  • iterator end () β€” iterator past the last char ✨
  • const_iterator end () const noexcept β€” const iterator past the last char πŸ”’
  • constexpr bool ends_with (_CharT __x) const noexcept β€” does she end with char __x? πŸŽ€
  • bool ends_with (_CharT __x) const noexcept β€” same, other overload πŸ’…
  • constexpr bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” ends with that string view? 🌸
  • bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” ends with that string view? (again) πŸ¦‹
  • constexpr bool ends_with (const _CharT *__x) const noexcept β€” ends with that C string? ⭐
  • bool ends_with (const _CharT *__x) const noexcept β€” ends with that C string? (again) πŸ’œ

  • iterator erase (__const_iterator __first, __const_iterator __last) β€” nukes a range βœ‚οΈ
  • iterator erase (__const_iterator __position) β€” nukes one char βœ‚οΈ
  • basic_string & erase (size_type __pos=0, size_type __n=_Base::npos) β€” nukes __n chars starting at __pos, defaults to everything πŸ’€
  • constexpr iterator erase (__const_iterator __first, __const_iterator __last) β€” Remove a range of characters. πŸŽ€
  • constexpr iterator erase (__const_iterator __position) β€” Remove one character. 🌸
  • iterator erase (iterator __first, iterator __last) β€” Remove a range of characters. πŸ¦‹
  • iterator erase (iterator __position) β€” Remove one character. ✨
  • constexpr basic_string & erase (size_type __pos=0, size_type __n=npos) β€” Remove characters. πŸ’œ

  • constexpr size_type find (_CharT __c, size_type __pos=0) const noexcept β€” Find position of a character. πŸ”
  • size_type find (_CharT __c, size_type __pos=0) const noexcept β€” Find position of a character. πŸ’…
  • constexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” searching a C substring, one flavor 🌸
  • constexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” Find position of a C substring. πŸ¦‹
  • size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” Find position of a C substring. πŸŽ€
  • constexpr size_type find (const _CharT *__s, size_type __pos=0) const noexcept β€” searching a C string, one flavor ✨
  • constexpr size_type find (const _CharT *__s, size_type __pos=0) const noexcept β€” Find position of a C string. ⭐
  • 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 β€” Find position of a string. πŸ‘‘
  • constexpr size_type find (_CharT __c, size_type __pos=0) const noexcept β€” Find position of a character. 🌈
  • constexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” Find position of a C substring. πŸ“
  • constexpr size_type find (const _CharT *__s, size_type __pos=0) const noexcept β€” Find position of a C string. πŸŽ€
  • constexpr size_type find (const basic_string &__str, size_type __pos=0) const noexcept β€” Find position of a string. πŸ’œ

  • constexpr size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexcept β€” Find position of a different character. πŸ•΅οΈ
  • size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexcept β€” Find position of a different character. πŸ’…
  • constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” first spot that is not part of that C substring πŸ”
  • constexpr size_type find_first_not_of (const _CharT *__s, size_type β€” and she continues into the next part, cliffhanger bestie πŸ˜­πŸ’–

Okay so, bestie, buckle up, because this next batch is the find family and there are... a lot of them πŸ’€ but like, in a good way, I promise.


πŸ” the find_first_not_of era (yes there are twelve of these, no I'm not kidding)

  • 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 β€” Find position of a character not in C substring.
  • constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexcept
  • 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.
  • 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 β€” Find position of a character not in string.
  • constexpr size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexcept β€” Find position of a different character.
  • 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.
  • 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.
  • 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.

Like, that's the whole vibe β€” first character that is not part of the set you gave it. Every overload you could ever want. iconic honestly 🌈

✨ and now find_first_of, the sequel nobody asked for but everybody needed

  • 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 β€” Find position of a character.
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept
  • 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 β€” Find position of a character of C substring.
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept β€” Find position of a character of C string.
  • 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 β€” Find position of a character of string.
  • constexpr size_type find_first_of (_CharT __c, size_type __pos=0) const noexcept β€” Find position of a character.
  • 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.
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept β€” Find position of a character of C string.
  • constexpr size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexcept β€” Find position of a character of string.

She's giving "I will find the FIRST one and I will find it politely." πŸ’…

πŸ¦‹ find_last_not_of β€” same energy, but backwards

  • constexpr size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a different character.
  • size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a different character.
  • constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept
  • 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 β€” Find last position of a character not in C substring.
  • constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos=_Base::npos) const noexcept
  • 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.
  • 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 β€” Find last position of a character not in string.
  • constexpr size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a different character.
  • 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.
  • 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.
  • 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.
Note bestie: the default here is npos, not 0. So if you don't hand it a __pos, it starts from the very back of the string and works its way forward. No cap. πŸ’–

πŸŽ€ find_last_of, closing out the find-iverse

  • constexpr size_type find_last_of (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a character.
  • size_type find_last_of (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a character.
  • constexpr size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept
  • 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 β€” Find last position of a character of C substring.
  • constexpr size_type find_last_of (const _CharT *__s, size_type __pos=_Base::npos) const noexcept
  • constexpr size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexcept β€” Find last position of a character of C string.
  • 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 β€” Find last position of a character of string.
  • constexpr size_type find_last_of (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a character.
  • 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.
  • constexpr size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexcept β€” Find last position of a character of C string.
  • constexpr size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexcept β€” Find last position of a character of string.

Bestie we SURVIVED the find overloads. Drink some water. πŸ“


🌸 the little guys (access + allocator)

  • constexpr const_reference front () const noexcept
  • constexpr reference front () noexcept
  • constexpr allocator_type get_allocator () const noexcept β€” Return copy of allocator used to construct this string.

front() gives you the very first character, and get_allocator() hands you back a copy of the allocator that built this string. ✨


πŸ’œ the insert family (prepare yourself, it's a big one)

  • iterator insert (__const_iterator __p, _CharT __c)
  • template<typename _InputIterator> iterator insert (__const_iterator __p, _InputIterator __first, _InputIterator __last)
  • iterator insert (const_iterator __p, size_type __n, _CharT __c)
  • iterator insert (const_iterator __p, std::initializer_list< _CharT > __l)
  • basic_string & insert (size_type __pos, const _CharT *__s)
  • basic_string & insert (size_type __pos, const _CharT *__s, size_type __n)
  • basic_string & insert (size_type __pos, size_type __n, _CharT __c)
  • basic_string & insert (size_type __pos1, const basic_string &__str)
  • basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n)
  • constexpr iterator insert (__const_iterator __p, _CharT __c) β€” Insert one character.
  • template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr iterator insert (const_iterator __p, _InputIterator __beg, _InputIterator __end) β€” Insert a range of characters.
  • 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.
  • iterator insert (iterator __p, _CharT __c) β€” Insert one character.
  • template<class _InputIterator> void insert (iterator __p, _InputIterator __beg, _InputIterator __end) β€” Insert a range of characters.
  • void insert (iterator __p, initializer_list< _CharT > __l) β€” Insert an initializer_list of characters.
  • void insert (iterator __p, size_type __n, _CharT __c) β€” Insert multiple characters.
  • constexpr basic_string & insert (size_type __pos, const _CharT *__s) β€” Insert a C string.
  • constexpr basic_string & insert (size_type __pos, const _CharT *__s, size_type __n) β€” Insert a C substring.
  • constexpr basic_string & insert (size_type __pos, size_type __n, _CharT __c) β€” Insert multiple characters.
  • constexpr basic_string & insert (size_type __pos1, const basic_string &__str) β€” Insert value of a string.
  • constexpr basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos) β€” Insert a substring.

The way that insert has TWENTY-TWO overloads and every single one of them is doing something slightly different... main character energy tbh πŸ‘‘


πŸ’« size check + the operators

  • constexpr size_type length () const noexcept β€” Returns the number of characters in the string, not including any null-termination.
  • constexpr size_type max_size () const noexcept β€” Returns the size() of the largest possible string.
  • basic_string & operator+= (_CharT __c)
  • basic_string & operator+= (const _CharT *__s)
  • basic_string & operator+= (const basic_string &__str)
  • basic_string & operator+= (std::initializer_list< _CharT > __l)
  • constexpr basic_string & operator+= (const basic_string &__str) β€” Append a string to this string.
  • basic_string & operator= (_CharT __c)
  • basic_string & operator= (basic_string &&)=default
  • basic_string & operator= (const _CharT *__s)
  • basic_string & operator= (const basic_string &)=default
  • basic_string & operator= (std::initializer_list< _CharT > __l)
  • reference operator[] (size_type __pos)
  • const_reference operator[] (size_type __pos) const noexcept
  • constexpr reference operator[] (size_type __pos) β€” Subscript access to the data contained in the string.
  • constexpr const_reference operator[] (size_type __pos) const noexcept β€” Subscript access to the data contained in the string.

length() counts your characters and deliberately skips the null terminator, so don't come for her when "hi" gives you 2. 🫢


🌈 the push/pop/reverse crew

  • void pop_back ()
  • void push_back (_CharT __c)
  • reverse_iterator rbegin ()
  • const_reverse_iterator rbegin () const noexcept
  • reverse_iterator rend ()
  • const_reverse_iterator rend () const noexcept

pop_back() yeets the last character, push_back() adds one at the end, and rbegin() / rend() give you the reverse iterators so you can stroll through your string backwards like it's a catwalk. πŸ’… Obsessed.

  • template<typename _InputIterator> basic_string & replace (__const_iterator __i1, __const_iterator __i2, _InputIterator __j1, _InputIterator __j2)
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s)
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s, size_type __n)
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, const basic_string &__str)
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, size_type __n, _CharT __c)
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, std::initializer_list< _CharT > __l)
  • basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s)
  • basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)
  • basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c)
  • basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str)
  • basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2)

like ok the replace family is a whole girl group with eleven members and honestly? each one ate πŸ’…

  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, _CharT *__k1, _CharT *__k2)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__k1, const _CharT *__k2)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s) β€” swap out that [__i1, __i2) range for a whole C string πŸŽ€
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s, size_type __n) β€” same vibe but you're only taking a C substring, no cap
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const basic_string &__str) β€” range out, string in, iconic behavior
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const_iterator __k1, const_iterator __k2)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, iterator __k1, iterator __k2)
  • constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, size_type __n, _CharT __c) β€” replace that range with multiple copies of one character 🫢
  • template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, _InputIterator __k1, _InputIterator __k2) β€” replace a range with another range, very "out with the old" energy ✨
  • constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, initializer_list< _CharT > __l) β€” replace a range with an initializer_list, so you can just vibe with braces πŸ’–
  • basic_string & replace (iterator __i1, iterator __i2, _CharT *__k1, _CharT *__k2)
  • template<class _InputIterator> basic_string & replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2) β€” replace a range with another range πŸ”₯
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__k1, const _CharT *__k2)
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s) β€” replace a range with a C string, mwah πŸ’‹
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s, size_type __n) β€” replace a range with a C substring
  • basic_string & replace (iterator __i1, iterator __i2, const basic_string &__str) β€” replace a range with a string, slay
  • basic_string & replace (iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2)
  • basic_string & replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l) β€” replace a range with an initializer_list πŸ¦‹
  • basic_string & replace (iterator __i1, iterator __i2, iterator __k1, iterator __k2)
  • basic_string & replace (iterator __i1, iterator __i2, size_type __n, _CharT __c) β€” replace a range with multiple copies of a character 🌸
  • constexpr basic_string & replace (size_type __pos, size_type __n, const basic_string &__str) β€” replace characters with the value of another string πŸ’œ
  • constexpr basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s) β€” replace characters with the 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
  • constexpr basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c) β€” replace characters with multiple copies of a character
  • constexpr basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) β€” replace characters with the value of another string (and yes bestie, __n2 defaults to npos)

ok breathe. that's the replace girlies. moving on 🧚

  • constexpr void reserve ()
  • constexpr void reserve (size_type __res_arg) β€” tries to preallocate enough memory for the number of characters you asked for
  • void reserve (size_type __res_arg) β€” same thing, tries to preallocate enough memory for the number of characters you asked for
  • constexpr void reserve (size_type __res_arg) β€” yeah it's here again, trying to preallocate enough memory for the number of characters πŸ’…
  • void resize (size_type __n)
  • void resize (size_type __n, _CharT __c)
  • constexpr void resize (size_type __n) β€” resizes the string to the number of characters you specified, periodt
  • constexpr void resize (size_type __n, _CharT __c) β€” resizes the string to the number of characters you specified ✨
  • constexpr size_type rfind (_CharT __c, size_type __pos=npos) const noexcept β€” find the last position of a character πŸ”
  • size_type rfind (_CharT __c, size_type __pos=npos) const noexcept β€” find the last position of a character (yes, again, she's popular)
  • constexpr size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const
  • 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 the last position of a C substring πŸŽ€
  • constexpr size_type rfind (const _CharT *__s, size_type __pos=_Base::npos) const
  • constexpr size_type rfind (const _CharT *__s, size_type __pos=npos) const β€” find the 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 the last position of a string
  • constexpr size_type rfind (_CharT __c, size_type __pos=npos) const noexcept β€” find the 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
  • constexpr size_type rfind (const _CharT *__s, size_type __pos=npos) const β€” find the 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 ⭐
  • void shrink_to_fit () noexcept
  • constexpr size_type size () const noexcept β€” hands you the number of characters in the string, and not counting any null-termination, ok? important πŸ’…
  • constexpr bool starts_with (_CharT __x) const noexcept
  • bool starts_with (_CharT __x) const noexcept
  • constexpr bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexcept
  • bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexcept
  • constexpr bool starts_with (const _CharT *__x) const noexcept
  • bool starts_with (const _CharT *__x) const noexcept
  • basic_string substr (size_type __pos=0, size_type __n=_Base::npos) const
  • constexpr basic_string substr (size_type __pos, size_type __n) &&
  • constexpr basic_string substr (size_type __pos=0) &&
  • constexpr basic_string substr (size_type __pos=0, size_type __n=npos) const β€” get yourself a substring, little slice of the main character πŸ“
  • 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
  • void swap (basic_string &__x) noexcept(/*conditional */)
  • constexpr void swap (basic_string &__s) noexcept β€” swap contents with another string, trading cards but make it C++ 🎴

πŸŽ€ Static Public Attributes πŸŽ€

  • static const size_type npos β€” the value that various member functions hand back when they fail. she's the "idk girl, not found" of the string world πŸ’€

πŸ”’ Protected Member Functions πŸ”’

  • constexpr void _M_swap (const _Safe_container &__x) const noexcept

🫢 Friends 🫢

  • template<typename _ItT, typename _SeqT, typename _CatT> class ::__gnu_debug::_Safe_iterator

✨ Detailed Description ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
class __gnu_debug::basic_string< _CharT, _Traits, _Allocator >

It's literally Class std::basic_string with safety/checking/debug instrumentation. so it's the same bestie you know and love, but she went to therapy and now she checks things πŸ’–


πŸ’œ Member Function Documentation πŸ’œ

  • 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], [inherited] β€” a non-standard version of resize_and_overwrite for C++11 and above 🌸
  • 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) [inherited] β€” same deal, a non-standard version of resize_and_overwrite for C++11 and above
  • 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], [inherited] β€” append a C substring ✨

Parameters

  • __s β€” the C string you're appending
  • __n β€” how many characters you're appending

Returns

A reference to this string 🫢

  • 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], [inherited] β€” append a string to this string πŸ’…

Parameters

  • __str β€” the string you're appending

Returns

A 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>>(), and resize().

like ok she's referenced by ten whole functions?? main character energy fr fr πŸ‘‘

✨ append β€” Append a substring ✨

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], [inherited]

okay bestie so this one is literally "glue a piece of another string onto the end of me" πŸ’…

Parameters πŸŽ€

  • __str β€” the string you're appending from, your source of truth fr.
  • __pos β€” index of the first character of str to append. like, where do we start copy-pasting from.
  • __n β€” the number of characters to append.

Returns πŸ’–

A reference to this string. (So you can chain, iykyk.)

Exceptions 🚨

std::out_of_range if __pos is not a valid index. Not it throwing at you because you gave it a nonsense position πŸ™ˆ

So the tea is: 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. So like, it doesn't blow up, it just gives you everything that's left. generous king behavior πŸ‘‘


✨ append β€” Append an initializer_list of characters ✨

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

[inline], [constexpr], [inherited]

bestie you can just yeet a whole initializer_list of characters onto the end. curly braces, go off πŸŽ€

Parameters 🌸

  • __l β€” the initializer_list of characters to append.

Returns πŸ’–

A reference to this string. iconic, chaining stays winning.


✨ append β€” Append multiple characters ✨

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], [inherited]

the "spam the same character" button, no cap πŸ’…

Parameters πŸŽ€

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

Returns πŸ’–

A reference to this string.

Appends __n copies of __c to this string. That's it. That's the whole vibe. 'a' x 5, boom, aaaaa ✨


✨ assign β€” Set value to contents of another string (move edition) ✨

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], [inherited]

Parameters 🌸

  • __str β€” source string to use.

Returns πŸ’–

A reference to this string.

This function sets this string to the exact contents of __str. And here's the important lil note: __str is a valid, but unspecified string. So like… it still exists, it's not broken, but do NOT go assuming what's inside it afterward. It's giving "don't look in the box" energy πŸ’€

fr fr, "valid but unspecified" means the standard won't tell you what it holds. Read it if you must, but don't count on anything.

✨ assign β€” Set value to a C substring ✨

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], [inherited]

Parameters πŸŽ€

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

Returns πŸ’–

A reference to this string.

This function sets the value of this string to the first __n characters of __s. And if __n is larger than the number of available characters in __s, the remainder of __s is used. so it's not gonna yell at you for over-asking, it just gives what it's got 🫢


✨ assign β€” Set value to contents of another string ✨

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], [inherited]

Parameters 🌸

  • __str β€” source string to use.

Returns πŸ’–

A 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(), and std::basic_stringbuf< char >::str().

look at her, she's popular, everybody calls her πŸ’…βœ¨


✨ assign β€” Set value to a substring of a 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], [inherited]

Parameters πŸŽ€

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

Returns πŸ’–

A 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. And if __n is larger than the number of available characters in __str, the remainder of __str is used. slice-and-dice but make it safe ✨


✨ assign β€” Set value to multiple characters ✨

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

[inline], [constexpr], [inherited]

Parameters 🌸

  • __n β€” length of the resulting string.
  • __c β€” the character to use.

Returns πŸ’–

A reference to this string.

This function sets the value of this string to __n copies of character __c. filling the whole thing with one letter, main character energy πŸŽ€


✨ at β€” Provides access to the data contained in the string ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n);

[inline], [nodiscard], [constexpr]

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. like she does the vibe check before letting you in, and honestly? queen behavior πŸ‘‘


✨ at β€” (the unsharing one) ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n);

[inline]

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. πŸ‘€


✨ at β€” (const flavored, with the tags) ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
const_reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n) const;

[inline], [nodiscard], [constexpr]

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. look but don't touch bestie πŸ™ˆ


✨ at β€” (const flavored, no tags) ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
const_reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n) const;

[inline]

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 β€” (inherited, read/write) ✨

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

[inline], [nodiscard], [constexpr], [inherited]

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.


✨ at β€” (inherited, const) ✨

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

[inline], [nodiscard], [constexpr], [inherited]

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 β€” (const) ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
const_reference
std::basic_string< _CharT, _Traits, _Allocator >::back () const;

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

Returns a read-only (constant) reference to the data at the last element of the string. just the last character, pls don't poke it πŸŽ€


✨ back β€” (read/write) ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
reference
std::basic_string< _CharT, _Traits, _Allocator >::back ();

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

Returns a read/write reference to the data at the last element of the string. last character, but you can edit her now πŸ’…


✨ capacity ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type
std::basic_string< _CharT, _Traits, _Allocator >::capacity () const;

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

Returns the total number of characters that the string can hold before needing to allocate more memory. like, how many more besties can she fit before she has to go shopping for a bigger place πŸ›οΈβœ¨


✨ compare β€” Compare to a string ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
int
std::basic_string< _CharT, _Traits, _Allocator >::compare (const basic_string< _CharT, _Traits, _Allocator > & __str) const;

[inline], [nodiscard], [constexpr]

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.

so basically: negative = she comes first, zero = twins, positive = she comes after. and if they're equal all the way through, the shorter one wins the "ordered first" spot πŸ†


✨ compare β€” Compare substring to a string ✨

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
int
std::basic_string< _CharT, _Traits, _Allocator >::compare (size_type __pos,
                                                           size_type __n,
                                                           const basic_string< _CharT, _Traits, _Allocator > & __str) const;

[inline], [nodiscard], [constexpr]

Compare substring to a string.

  • __pos β€” index of the first character of the substring 🎯
  • __n β€” how many characters are in that substring
  • __str β€” the string you're comparing against

Returns β€” an integer that's < 0, 0, or > 0.

So here's the tea, bestie: you form the substring of this string out of the __n characters starting at __pos. Then: integer < 0 if that substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. It figures out the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). Then it compares the two by calling traits::compare(substring.data(),str.data(),rlen). If that comparison comes back nonzero it just returns it β€” otherwise the shorter one is ordered first. Periodt. πŸ’…


πŸ’– Compare substring to a string (yes, again, but a different overload)

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> int std::basic_string<
    _CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n,
    const basic_string< _CharT, _Traits, _Allocator > & __str) const
    [inline]

Okay so this one is literally the compare-substring-to-a-string, the standard-issue one, marked [inline]. 🌸

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 to a C string

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> int std::basic_string<
    _CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n1,
    const _CharT * __s) const [inline],  [nodiscard],  [constexpr]

Look at those attributes bestie β€” [inline], [nodiscard], and [constexpr]. It's giving overachiever. πŸ‘‘

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 against a character array

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> int std::basic_string<
    _CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n1,
    const _CharT * __s, size_type __n2) const [inline],  [nodiscard],
    [constexpr]

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. Not me warning you twice β€” it really does not care about your null terminator, bestie. 😭

🌈 Compare substring against a character array (the [inline]-only twin)

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> int std::basic_string<
    _CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n1,
    const _CharT * __s, size_type __n2) const [inline]

Same energy, just [inline] with no extra flair. Lowkey iconic. ⭐

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. 🫢

πŸ’… Compare substring to a substring (a.k.a. the double-substring situation)

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

Two positions, two lengths, one vibe check. Note the __n2 = npos default β€” it'll just run to the end of __str unless you say otherwise. πŸ¦‹

Parameters

  • __pos1 β€” index of first character of substring.
  • __n1 β€” number of characters in substring.
  • __str β€” string to compare against.
  • __pos2 β€” index of first character of substring of str.
  • __n2 β€” number of characters in 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 returns it, otherwise the shorter one is ordered first. 🧚


πŸ‘‘ Compare substring to a substring, again

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

Yeah bestie, it's the same overload again, just the [inline]-without-[nodiscard]/[constexpr] version. The header really said "here's both, choose your fighter." πŸ’€

Parameters

  • __pos1 β€” index of first character of substring.
  • __n1 β€” number of characters in substring.
  • __str β€” string to compare against.
  • __pos2 β€” index of first character of substring of str.
  • __n2 β€” number of characters in 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 returns it, otherwise the shorter one is ordered first. πŸ’–


🌟 Compare substring to a string β€” the inherited 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 [inline],  [nodiscard],  [constexpr],  [inherited]

Notice the template params dropped their defaults here, and it picked up [inherited] β€” it's getting passed down the family line. Main character energy, fr fr. πŸ”₯

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 to a C string β€” inherited edition

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 [inline],  [nodiscard],
    [constexpr],  [inherited]

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 against a character array β€” inherited edition

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 [inline],
    [nodiscard],  [constexpr],  [inherited]

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. Then form a string from the first __n2 characters of __s. It hands back an integer that's < 0 if this substring sorts before the string made from __s, 0 if their values are equivalent, or > 0 if this substring sorts after it. πŸ’…

It figures out the effective length rlen of the strings to compare as the smallest of the length of the substring and __n2. Then it compares the two strings by calling traits::compare(substring.data(),s,rlen). If the result of that comparison is nonzero it just returns it, otherwise the shorter one is ordered first. ✨

NB: s must have at least n2 characters, and '\0' has no special meaning here. no cap.

compare β€” substring vs. 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], [nodiscard], [constexpr], [inherited]

Ok so this one is compare substring to a substring. πŸ¦‹

Parameters

  • __pos1 β€” Index of first character of substring.
  • __n1 β€” Number of characters in substring.
  • __str β€” String to compare against.
  • __pos2 β€” Index of first character of substring of str.
  • __n2 β€” Number of characters in 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. It returns an integer that's < 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. It determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. Then it 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 a 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], [inherited]

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().

It copies up to __n characters starting at __pos into the C string __s. If __pos is greater than size(), out_of_range gets thrown. πŸ’€


data β€” non-const pointer to the contents ✨

template<typename _CharT, typename _Traits, typename _Alloc>
_CharT* std::basic_string<_CharT, _Traits, _Alloc>::data();

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

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. πŸ‘‘


empty β€” is it giving nothing? 🎈

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
bool std::basic_string<_CharT, _Traits, _Allocator>::empty() const;

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

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


erase β€” removing characters, five whole ways πŸ’…

erase β€” remove a range (const_iterator version)

template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(
    __const_iterator __first, __const_iterator __last);

[inline], [constexpr], [inherited]

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.

It removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. 🫢

erase β€” remove one character (const_iterator version)

template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(
    __const_iterator __position);

[inline], [constexpr], [inherited]

Remove one character.

Parameters

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

Returns

iterator referencing same location after removal.

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

erase β€” remove a range (iterator version)

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::iterator
std::basic_string<_CharT, _Traits, _Alloc>::erase(iterator __first,
    iterator __last);

[inherited]

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.

It removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. ✨

erase β€” remove one character (iterator version)

template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(
    iterator __position);

[inline], [inherited]

Remove one character.

Parameters

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

Returns

iterator referencing same location after removal.

It removes the character at __position from this string. The value of the string doesn't change if an error is thrown. πŸŽ€

erase β€” remove characters by index + count

template<typename _CharT, typename _Traits, typename _Alloc>
basic_string& std::basic_string<_CharT, _Traits, _Alloc>::erase(
    size_type __pos = 0, size_type __n = npos);

[inline], [constexpr], [inherited]

Remove characters.

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.

It 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 gets 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. 😭

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


find β€” the search era πŸ”

find β€” position of a character

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(_CharT __c,
    size_type __pos = 0) const;

[nodiscard], [constexpr], [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, it searches forward for __c within this string. If found, it returns the index where it was found. If not found, it returns npos. πŸ’…

find β€” position of a character (second overload)

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(_CharT __c,
    size_type __pos = 0) const;

[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, it searches forward for __c within this string. If found, it returns the index where it was found. If not found, it returns npos. ✨

find β€” position of a C substring

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(const _CharT* __s,
    size_type __pos, size_type __n) const;

[nodiscard], [constexpr], [noexcept]

Find position of a C substring.

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, it searches forward for the first __n characters in __s within this string. If found, it returns the index where it begins. If not found, it returns npos. πŸ¦‹

find β€” position of a C substring (second overload)

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(const _CharT* __s,
    size_type __pos, size_type __n) const;

[noexcept]

Find position of a C substring.

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, it searches forward for the first __n characters in __s within this string. If found, it returns the index where it begins. If not found, it returns npos. 🌸

find β€” position of a C string

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(const _CharT* __s,
    size_type __pos = 0) const;

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

Find position of a C string.

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, it searches forward for the value of __s within this string. If found, it returns the index where it begins. If not found, it returns npos. 🫢

find β€” position of a string

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(
    const basic_string<_CharT, _Traits, _Allocator>& __str,
    size_type __pos = 0) const;

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

Find position of a string.

Parameters

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

Returns

Index of start of first occurrence.

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

find β€” position of a string (second overload)

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(
    const basic_string<_CharT, _Traits, _Allocator>& __str,
    size_type __pos = 0) const;

[inline], [noexcept]

Find position of a string.

Parameters

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

Returns

Index of start of first occurrence.

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

find πŸ”

find β€” _CharT __c πŸ’…

   template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
       _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
       _Alloc >::find (_CharT __c, size_type __pos = 0) const [nodiscard],
       [constexpr],  [noexcept],  [inherited]

Okay bestie, this one is literally "find position of a character". πŸ” No cap.

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 __c within this string. If found, returns the index where it was found. If not found, returns npos.

References npos, and std::size().

find β€” const _CharT * __s, size_type __pos, size_type __n πŸ¦‹

   template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
       _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
       _Alloc >::find (const _CharT * __s, size_type __pos, size_type __n)
       const [nodiscard],  [constexpr],  [noexcept],  [inherited]

Find position of a C substring. It's giving "substring hunt". ✨

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().

find β€” const _CharT * __s, size_type __pos = 0 🌈

   template<typename _CharT, typename _Traits, typename _Alloc> size_type
       std::basic_string< _CharT, _Traits, _Alloc >::find (const _CharT * __s,
       size_type __pos = 0) const [inline],  [nodiscard],  [constexpr],
       [noexcept],  [inherited]

Find position of a C string. It's like, the C-string vibe check. πŸ¦‹

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.


find β€” const basic_string<...>& __str, size_type __pos = 0 πŸŽ€

   template<typename _CharT, typename _Traits, typename _Alloc> size_type
       std::basic_string< _CharT, _Traits, _Alloc >::find (const basic_string<
       _CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const [inline],
       [nodiscard],  [constexpr],  [noexcept],  [inherited]

Find position of a string. Bestie string searching realness. πŸ’–

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.


find_first_not_of πŸ’–

find_first_not_of β€” _CharT __c (default template args) πŸ™ˆ

   template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
       typename _Allocator = std::allocator<_CharT>> size_type
       std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
       (_CharT __c, size_type __pos = 0) const [nodiscard],  [constexpr],
       [noexcept]

Find position of a different character. It's giving "not this one". πŸ’…

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.


find_first_not_of β€” _CharT __c (default template args, [noexcept] only) 😭

   template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
       typename _Allocator = std::allocator<_CharT>> size_type
       std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
       (_CharT __c, size_type __pos = 0) const [noexcept]

Find position of a different character. Same vibe, just [noexcept] and no [nodiscard]/[constexpr]. 🫢

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.


find_first_not_of β€” const _CharT * __s, size_type __pos, size_type __n (default template args) πŸ¦‹

   template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
       typename _Allocator = std::allocator<_CharT>> size_type
       std::basic_string< _CharT, _Traits, _Allocator >::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. Avoiding characters like a pro. ✨

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.


find_first_not_of β€” const _CharT * __s, size_type __pos, size_type __n (default template args, [noexcept] only) 😭

   template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
       typename _Allocator = std::allocator<_CharT>> size_type
       std::basic_string< _CharT, _Traits, _Allocator >::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 as above but lowkey only [noexcept]. πŸ™ˆ

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.


find_first_not_of β€” const _CharT * __s, size_type __pos = 0 (default template args) 🌈

   template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
       typename _Allocator = std::allocator<_CharT>> size_type
       std::basic_string< _CharT, _Traits, _Allocator >::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. C-string avoidance, slay. πŸ’…

Parameters

  • __s β€” C 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 __s within this string. If found, returns the index where it was found. If not found, returns npos.


find_first_not_of β€” const basic_string<...>& __str, size_type __pos = 0 (default template args) πŸŽ€

   template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
       typename _Allocator = std::allocator<_CharT>> size_type
       std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
       (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type
       __pos = 0) const [inline],  [nodiscard],  [constexpr],  [noexcept]

Find position of a character not in string. String bestie avoidance. πŸ’–

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_not_of β€” const basic_string<...>& __str, size_type __pos = 0 (default template args, [noexcept] only) 😭

   template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
       typename _Allocator = std::allocator<_CharT>> size_type
       std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
       (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type
       __pos = 0) const [inline],  [noexcept]

Find position of a character not in string. Just [noexcept], no frills. 🫢

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_not_of β€” _CharT __c (inherited) πŸ‘‘

   template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
       _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
       _Alloc >::find_first_not_of (_CharT __c, size_type __pos = 0) const
       [nodiscard],  [constexpr],  [noexcept],  [inherited]

Find position of a different character. This one is [inherited], periodt. πŸ’…

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.

References npos, and std::size().

find_first_not_of β€” const _CharT * __s, size_type __pos, size_type __n (inherited) πŸ¦‹

   template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
       _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
       _Alloc >::find_first_not_of (const _CharT * __s, size_type __pos,
       size_type __n) const [nodiscard],  [constexpr],  [noexcept],
       [inherited]

Find position of a character not in C substring. Inherited energy. ✨

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().

find_first_not_of β€” const _CharT * __s, size_type __pos = 0 (inherited) 🌈

   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],  [nodiscard],
       [constexpr],  [noexcept],  [inherited]

Find position of a character not in C string. Inherited C-string avoidance. πŸ’–

Parameters

  • __s β€” C 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 __s within this string. If found, returns the index where it was found. If not found, returns npos.


find_first_not_of β€” const basic_string<...>& __str, size_type __pos = 0 (inherited) πŸŽ€

   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],  [inherited]

Find position of a character not in string. Inherited string avoidance, final boss. πŸ‘‘

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.

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().
heads up bestie, this stretch is pure overload energy β€” same function name, a whole fleet of flavors, and every single one is getting its moment. no skipping, no merging, we're doing all of them. πŸ’…
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (_CharT __c,
    size_type __pos = 0) const

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

Find position of a character. πŸ’–

  • __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).

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

specifiers: [inline], [noexcept]

Find position of a character. πŸ¦‹ (yes, same vibe, slightly different specifier list β€” the way that they're separate entries and we're keeping both. periodt.)

  • __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).

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (const
    _CharT * __s, size_type __pos, size_type __n) const

specifiers: [nodiscard], [constexpr], [noexcept]

Find position of a character of C substring. 🌸

  • __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.


template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (const
    _CharT * __s, size_type __pos, size_type __n) const

specifiers: [noexcept]

Find position of a character of C substring. πŸŽ€

  • __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.


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

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

Find position of a character of C string. ✨

  • __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.


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

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

Find position of a character of string. 🫢

  • __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.


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

specifiers: [inline], [noexcept]

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

  • __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.


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

specifiers: [inline], [nodiscard], [constexpr], [noexcept], [inherited]

Find position of a character. 🌈 (inherited flavor, iconic behavior)

  • __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).

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

specifiers: [nodiscard], [constexpr], [noexcept], [inherited]

Find position of a character of C substring. πŸ’«

  • __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().


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

specifiers: [inline], [nodiscard], [constexpr], [noexcept], [inherited]

Find position of a character of C string. πŸ“

  • __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.


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

specifiers: [inline], [nodiscard], [constexpr], [noexcept], [inherited]

Find position of a character of string. 🧚

  • __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().


πŸŒ™ and now the backwards girlies: find_last_not_of πŸŒ™

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

specifiers: [nodiscard], [constexpr], [noexcept]

Find last position of a different character. πŸ™ˆ

  • __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.


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

specifiers: [noexcept]

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

  • __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.


template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of
    (const _CharT * __s, size_type __pos, size_type __n) const

specifiers: [nodiscard], [constexpr], [noexcept]

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

  • __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.


template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of
    (const _CharT * __s, size_type __pos, size_type __n) const

specifiers: [noexcept]

Find last position of a character not in C substring. πŸŽ€

  • __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.


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

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

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

okay so that last find_last_not_of overload was mid-explanation β€” here's the rest of its tea, bestie:

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 basic_string bestie (with _Allocator)

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]

Find last position of a character not in string. πŸŽ€

Parameters

  • __str β€” 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 __str within this string. If found, returns the index where it was found. If not found, returns npos. periodt ✨


πŸ’œ same energy, less constexpr

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [noexcept]

Find last position of a character not in string.

Parameters

  • __str β€” 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 __str within this string. If found, returns the index where it was found. If not found, returns npos. no notes πŸ’–


πŸ¦‹ find_last_not_of β€” the single-char version (inherited)

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], [inherited]

Find last position of a different character. it's giving "not this one, literally anything but this one" πŸ™ˆ

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 β€” C substring edition (inherited)

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], [inherited]

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 β€” plain C string edition (inherited)

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], [inherited]

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. iconic πŸ’…


πŸŽ€ find_last_not_of β€” basic_string edition (inherited)

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], [inherited]

Find last position of a character not in string.

Parameters

  • __str β€” 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 __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_last_not_of(), std::basic_string< _CharT >::find_last_not_of(), and std::basic_string< _CharT, std::char_traits< _CharT >, std::allocator< _CharT > >::swap(). look at her being popular πŸ’–


πŸ”₯ find_last_of β€” single char, the constexpr one

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (_CharT __c, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [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.

Note: equivalent to rfind(__c, __pos).

✨ find_last_of β€” same but no constexpr

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::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 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.

Note: equivalent to rfind(__c, __pos).

🌸 find_last_of β€” C substring, constexpr era

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::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 characters to locate.
  • __pos β€” Index of character to search back from.
  • __n β€” Number of characters from s to search for.

Returns

Index of last occurrence.

Starting from __pos, searches backward 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_last_of β€” C substring, no constexpr

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::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 character to search back from.
  • __n β€” Number of characters from s to search for.

Returns

Index of last occurrence.

Starting from __pos, searches backward 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_last_of β€” whole C string

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::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 characters to locate.
  • __pos β€” Index of character to search back from (default end).

Returns

Index of last occurrence.

Starting from __pos, 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. slay 🌟


πŸ“ find_last_of β€” basic_string, constexpr edition

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]

Find last position of a character of string.

Parameters

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

Returns

Index of last occurrence.

Starting from __pos, searches backward 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_of β€” basic_string, no constexpr

template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (const basic_string< _CharT, _Traits, _Allocator > & __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 character to search back from (default end).

Returns

Index of last occurrence.

Starting from __pos, searches backward 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_of β€” single char (inherited)

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], [inherited]

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.

Note: equivalent to rfind(__c, __pos).

🧚 find_last_of β€” C substring (inherited)

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], [inherited]

Find last position of a character of C substring.

Parameters

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

Returns

Index of last occurrence.

Starting from __pos, it searches backward for one of the first __n characters of __s inside this string. Found it? You get the index where it was. Not found? You get npos. That's it, that's the whole story. πŸ’…

References npos, and std::size().


find_last_of β€” the C-string glow-up ✨

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], [inherited]

Find last position of a character of C string.

Parameters

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

Returns Index of last occurrence.

Starting from __pos, it searches backward for one of the characters of __s inside this string. If it finds one, it returns the index where it was found. If not found, it returns npos. bestie it really said "no character, no answer". 🫢


find_last_of β€” the string-object 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], [nodiscard], [constexpr], [noexcept], [inherited]

Find last position of a character of string.

Parameters

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

Returns Index of last occurrence.

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

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


front β€” meet the first character πŸ‘‘

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> const_reference
std::basic_string< _CharT, _Traits, _Allocator >::front () const

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

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

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> reference
std::basic_string< _CharT, _Traits, _Allocator >::front ()

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

Returns a read/write reference to the data at the first element of the string. Now you can touch. main character energy fr. πŸ’…


get_allocator β€” receipts on the allocator 🧾

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> allocator_type
std::basic_string< _CharT, _Traits, _Allocator >::get_allocator () const

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

Return copy of allocator used to construct this string. Like, who's been managing this memory the whole time? Here's their @. πŸ’–


insert β€” one character, const_iterator edition πŸŽ€

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

[inline], [constexpr], [inherited]

Insert one character.

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 the position referenced by __p. If adding the character causes the length to exceed max_size(), length_error is thrown. If __p is beyond end of string, out_of_range is thrown. And the good news: the value of the string doesn't change if an error is thrown. no half-finished slay. ✨


insert β€” a whole range, const_iterator edition 🌈

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], [inherited]

Insert a range of characters.

Parameters

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

Returns Iterator referencing the first inserted char.

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.


insert β€” the initializer_list, const_iterator edition πŸ¦‹

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

[inline], [constexpr], [inherited]

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().

insert β€” multiple copies, const_iterator edition πŸ’œ

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], [inherited]

Insert multiple characters.

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.

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().


insert β€” one character, plain iterator edition 🌟

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

[inline], [inherited]

Insert one character.

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 the position referenced by __p. If adding the 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.


insert β€” a range, plain iterator edition 🌺

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], [inherited]

Insert a range of characters.

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.


insert β€” initializer_list, plain iterator edition πŸ“

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

[inline], [inherited]

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().

insert β€” multiple copies, plain iterator edition πŸ’«

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

[inline], [inherited]

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.


insert β€” the C string drop-in πŸ”₯

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

[inline], [constexpr], [inherited]

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.


insert β€” the C substring glow 🧚

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], [inherited]

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.


insert β€” the repeat-button edition, by index πŸ‘‘

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], [inherited]

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.

🫢 insert β€” slide a whole string in

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], [inherited]

Insert value of a string. bestie it does exactly what it says on the tin ✨

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().

So the vibe is: it inserts the value of __str starting at __pos1. If adding characters causes the length to exceed max_size(), length_error is thrown. And the glow-up rule: the value of the string doesn't change if an error is thrown. no cap 🧚


πŸŽ€ insert β€” but make it a substring

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], [inherited]

Insert a substring. yes queen, selective insertion 😌

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().

Starting at pos1, insert __n character of __str beginning with __pos2. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos1 is beyond the end of this string or __pos2 is beyond the end of __str, out_of_range is thrown. The value of the string doesn't change if an error is thrown. πŸ’€ she's dramatic but she's honest


πŸ¦‹ length β€” how many characters we got

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::length () const

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

Returns the number of characters in the string, not including any null-termination. periodt. she's not counting that sneaky null terminator, she's better than that πŸ‘‘


🌸 max_size β€” the ceiling, the limit, the vibe check

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::max_size () const

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

Returns the size() of the largest possible string. the absolute biggest she can be, iconic πŸ’œ


⭐ operator+= β€” append era

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], [inherited]

Append a string to this string. just tacking it right on the end, lowkey the most used thing ever 😭

Parameters

  • __str β€” The string to append.

Returns

Reference to this string. 🫢


πŸ’… operator[] β€” the non-const one, she's editable

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

[inline], [nodiscard], [constexpr], [inherited]

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().)

fr fr bestie, this one does NOT check your bounds. she will simply let you walk off the edge. if you want a seatbelt, go see at(). 🚨

πŸ’œ operator[] β€” the const one, she's read-only and that's her whole thing

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

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

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 she's listed six whole times, the algorithm said so, we don't question the algorithm)


🌈 replace β€” range of characters gets swapped 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], [inherited]

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 β€” range gets swapped for a C *sub*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, size_type __n)

[inline], [constexpr], [inherited]

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 β€” range gets swapped for 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], [inherited]

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 β€” range gets swapped for a bunch of 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], [inherited]

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 β€” range gets swapped for another range (const_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], [inherited]

Replace range of characters with range.

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 β€” range gets swapped for an initializer_list

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], [inherited]

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. πŸ’€ (yes, the text really says [__k1,__k2) here even though the parameter is named __l β€” that's literally what the page says, so we're saying it too, no edits, no cap)


πŸ’œ replace β€” range gets swapped for another range (iterator edition)

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], [inherited]

Replace range of characters with range.

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 β€” range gets swapped for a C string (iterator edition)

template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const _CharT * __s)

[inline], [inherited]

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 β€” swap a whole range for a chunk of a C string

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],  [inherited]

okay so this is the "Replace range of characters with C substring" girly πŸ’… you hand her two iterators and she just deletes the whole vibe between them, then drops in the first __n characters of __s like it's nothing.

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. (she gives herself back, main character energy πŸ‘‘)

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 β€” swap a whole range for a whole other 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],  [inherited]

Replace range of characters with string. literally the same as above but your source is a basic_string instead of a C string, so no __n required, she takes the whole thing 🫢

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 β€” swap a whole range for an 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],  [inherited]

Replace range of characters with initializer_list. curly-brace girlies rise up πŸŽ€

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 β€” swap a whole range for a bunch of copies of one char

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],  [inherited]

Replace range of characters with multiple characters. yes bestie, she will absolutely print the same character __n times for you, no judgement πŸ’œ

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 β€” index-based, whole other string

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],  [inherited]

Replace characters with value from another string. notice we've switched from iterators to indexes here β€” she contains multitudes ✨

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 β€” okay so this one is iconic and everyone wants a piece of her 😭 here is the full guest list, and no I did not make any of these up:

  • 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()
  • std::basic_string< _CharT >::replace()

(that's nine insert()s and eleven replace()s, fr fr β€” they're all the same name because they're different overloads, the page just lists them like this πŸ™ˆ)


🌸 replace β€” index-based, plain C string

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],  [inherited]

Replace characters with value of a C string. she takes all of __s, zero counting, we love a low-effort queen 🌈

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 β€” index-based, C *sub*string

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],  [inherited]

Replace characters with value of a C substring. now you do get to say how much of __s you want, and she'll be chill about it πŸ¦‹

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 β€” index-based, __n2 copies of one char

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],
    [inherited]

Replace characters with multiple characters. four arguments, one job: out with __n1, in with __n2 copies of __c πŸ’…

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 β€” index-based, slice of another string

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],
    [inherited]

Replace characters with value from another string. this is the deluxe version bestie β€” you get to pick where in __str to start (__pos2) and how much of it to take (__n2), and __n2 even defaults to npos so she'll just grab the rest if you don't say 🌟

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 β€” the no-argument one (plot twist: it shrinks)

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> void std::basic_string<
    _CharT, _Traits, _Allocator >::reserve () [constexpr]

Equivalent to shrink_to_fit().

not me expecting "reserve" to reserve something 😭 with zero arguments she does the literal opposite, she lets go. it's giving "decluttering era". πŸ’€

🧚 reserve(size_type __res_arg) β€” preallocate like a girlboss

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> void std::basic_string<
    _CharT, _Traits, _Allocator >::reserve (size_type __res_arg) [constexpr]

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.


🧚 reserve(size_type __res_arg) β€” same energy, different declaration

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> void std::basic_string<
    _CharT, _Traits, _Allocator >::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().

okay so real talk, this function is literally trying to reserve enough memory for the string to hold the number of characters you asked for. If what you asked for is more than max_size(), then length_error gets thrown, no cap. πŸ’€

The whole glow-up here is: if you need optimal code and you actually know how long your string is gonna be, you can reserve that memory up front and prevent a possible reallocation of memory and copying of string data. Pre-planning? iconic. πŸ‘‘


✨ reserve (the constexpr one) ✨

template<typename _CharT, typename _Traits, typename _Alloc>
void std::basic_string< _CharT, _Traits, _Alloc >::reserve(size_type __res_arg) [constexpr], [inherited]

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. so smart, bestie.

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().


🌸 resize (one arg) 🌸

template<typename _CharT, typename _Traits, typename _Alloc>
void std::basic_string< _CharT, _Traits, _Alloc >::resize(size_type __n) [inline], [constexpr], [inherited]

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. so like, they get the ol' zero treatment.


πŸ¦‹ resize (two args) πŸ¦‹

template<typename _CharT, typename _Traits, typename _Alloc>
void std::basic_string< _CharT, _Traits, _Alloc >::resize(size_type __n, _CharT __c) [constexpr], [inherited]

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.

References append(), erase(), and size().

Referenced by std::basic_string< _CharT >::resize().


πŸŽ€ rfind (template, _CharT overload, constexpr version) πŸŽ€

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(_CharT __c, size_type __pos = npos) const [nodiscard], [constexpr], [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 (template, _CharT overload, non-constexpr version) πŸŽ€

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::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 (template, C substring, constexpr version) 🌈

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [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 (template, C substring, non-constexpr version) 🌈

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::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 (template, C string) ⭐

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const _CharT * __s, size_type __pos = npos) const [inline], [nodiscard], [constexpr]

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.


πŸ’– rfind (template, basic_string, constexpr + noexcept version) πŸ’–

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]

Find last position of a string. πŸ¦‹

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.


πŸ’– rfind (template, basic_string, noexcept-only version) πŸ’–

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [noexcept]

Find last position of a string. πŸ¦‹

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.


πŸ‘‘ rfind (inherited, _CharT overload) πŸ‘‘

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], [inherited]

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.

References npos, and std::size().


πŸ‘‘ rfind (inherited, C substring) πŸ‘‘

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], [inherited]

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.

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


🌟 rfind (inherited, C string) 🌟

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], [inherited]

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.


🌟 rfind (inherited, basic_string) 🌟

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], [inherited]

Find last position of a string. πŸ¦‹

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.

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().


πŸ“ size πŸ“

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
         typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::size() const [inline], [nodiscard], [constexpr], [noexcept]

Returns the number of characters in the string, not including any null-termination. so like, the actual vibes count, not the sneaky hidden \0 at the end, iykyk.


🧚 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], [inherited]

Get a substring. βœ‚οΈ

okay bestie we're in the home stretch of the member function tour and honestly this part ate πŸ’…


  • __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().

So the vibe here is: it constructs and returns a brand new string, built from the __n characters that start at __pos. If your string is too short? No stress, it just uses the remainder of the characters. But if __pos is past the end of the string, out_of_range gets yeeted at you. 🫢


the subview one, take one πŸ¦‹

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],  [inherited]

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().

It constructs and returns a subview using the __n characters starting at __pos. If the string is too short, it uses the remainder of the characters. And if __pos is beyond the end of the string, out_of_range is thrown. periodt.


the subview one, take two πŸ‘‘ (yes, the page really does list it twice β€” icon behaviour, we don't question it)

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],  [inherited]

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().

Constructs and returns a subview using the __n characters starting at __pos. Too short a string? It uses the remainder of the characters. __pos past the end of the string? out_of_range is thrown. same energy, same facts, no notes πŸ’…


swap β€” the trade 🀝

template<typename _CharT, typename _Traits, typename _Alloc> void
    std::basic_string< _CharT, _Traits, _Alloc >::swap (basic_string<
    _CharT, _Traits, _Alloc > & __s) [constexpr],  [noexcept],  [inherited]

Swap contents with another string.

Parameters

  • __s β€” String to swap with.

It exchanges the contents of this string with that of __s in constant time. literally the fastest glow-up in the whole file, no cap. ✨

References basic_string(), and get_allocator().

Referenced by std::basic_string< _CharT >::assign(), and std::basic_string< _CharT >::operator=().


πŸ’œ Member Data Documentation πŸ’œ

npos β€” the fail state, but make it static πŸŽ€

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>> const size_type
    std::basic_string< _CharT, _Traits, _Allocator >::npos [static]

Value returned by various member functions when they fail. yes bestie, npos is the group chat's "something went wrong" text. πŸ’€


✨ Author ✨

Generated automatically by Doxygen for libstdc++ from the source code.


and that's a wrap on the whole page, bestie!! πŸŽ‰ you read all 15 parts, which is genuinely main character energy. go hydrate, go compile something, go be iconic. πŸ¦‹πŸ’–

this was sourced from libstdc++, page __gnu_debu...llocator >(3), straight outta the libstdc++ manual pages β€” mwah, no cap, slay πŸ’…πŸŒˆ

πŸ“¦ 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