__GNU_DEBUG::BASIC_STRING(3cxx)

πŸ’– NAME πŸ’–

Okay so this is the __gnu_debug::ba...s, _Allocator >(3cxx) manual page, and the main character is __gnu_debug::basic_string< _CharT, _Traits, _Allocator >. It’s the class std::basic_string with safety/checking/debug instrumentation. No cap, bestie β€” it’s giving string energy with debug instrumentation in the mix. πŸŽ€

✨ SYNOPSIS ✨

First things first, include the header:

#include <string>

It inherits from __gnu_debug::_Safe_container< _SafeContainer, _Alloc, _SafeBase, _IsCxx11AllocatorAware > and std::basic_string< _CharT, _Traits, _Alloc >. Slay. πŸ¦‹

🫢 Public Types 🫢

  • allocator_type β€” typedef _Allocator allocator_type; that’s the allocator type, periodt. πŸ’…
  • const_iterator β€” typedef __gnu_debug::_Safe_iterator< typename _Base::const_iterator, basic_string > const_iterator; the checked const iterator vibe. ✨
  • const_pointer β€” typedef _Base::const_pointer const_pointer; the const pointer type. πŸŽ€
  • const_reference β€” typedef _Base::const_reference const_reference; the const reference type. 🌸
  • const_reverse_iterator β€” typedef std::reverse_iterator< const_iterator > const_reverse_iterator; reverse iterator but const, iconic. πŸ¦‹
  • difference_type β€” typedef _Base::difference_type difference_type; the difference type. πŸ’œ
  • iterator β€” typedef __gnu_debug::_Safe_iterator< typename _Base::iterator, basic_string > iterator; the checked iterator, lowkey essential. πŸ”₯
  • pointer β€” typedef _Base::pointer pointer; the pointer type. ⭐
  • reference β€” typedef _Base::reference reference; the reference type. 🫢
  • reverse_iterator β€” typedef std::reverse_iterator< iterator > reverse_iterator; reverse iterator energy, fr fr. 🌈
  • size_type β€” typedef _Base::size_type size_type; the size type. πŸ“
  • traits_type β€” typedef _Traits traits_type; the traits type. 🧚
  • value_type β€” typedef _Traits::char_type value_type; the character type, and yes it’s giving main-character energy. πŸ‘‘

🌸 Public Member Functions 🌸

okay bestie, this is the whole entire menu of what she can do πŸ’– every overload, every default argument, nothing skipped, nothing merged. grab a lil snack, we're going through all of it.

  • basic_string (_Base &&__base) noexcept β€” the _Base rvalue-ref constructor, and she's noexcept about it ✨
  • template<typename _InputIterator > basic_string (_InputIterator __begin, _InputIterator __end, const _Allocator &__a=_Allocator()) β€” build her from an iterator range, allocator defaults to _Allocator()
  • basic_string (basic_string &&)=default β€” the move constructor, defaulted, no notes πŸ’…
  • basic_string (basic_string &&__s, const _Allocator &__a) noexcept(std::is_nothrow_constructible< _Base, _Base, const _Allocator & >::value) β€” move with an allocator, and the noexcept is that whole is_nothrow_constructible expression, iykyk
  • basic_string (const _Allocator &__a) noexcept β€” just an allocator, that's it, noexcept
  • basic_string (const _Base &__base) β€” the _Base const-ref constructor
  • basic_string (const _CharT *__s, const _Allocator &__a=_Allocator()) β€” from a _CharT pointer, allocator defaults
  • basic_string (const _CharT *__s, size_type __n, const _Allocator &__a=_Allocator()) β€” pointer plus a count __n, allocator defaults
  • basic_string (const basic_string &)=default β€” copy constructor, defaulted 🫢
  • basic_string (const basic_string &__s, const _Allocator &__a) β€” copy, but you're bringing your own allocator
  • basic_string (const basic_string &__str, size_type __pos, size_type __n=_Base::npos, const _Allocator &__a=_Allocator()) β€” the substring constructor; __n defaults to _Base::npos, allocator defaults too
  • basic_string (size_type __n, _CharT __c, const _Allocator &__a=_Allocator()) β€” __n copies of character __c, allocator defaults
  • basic_string (std::initializer_list< _CharT > __l, const _Allocator &__a=_Allocator()) β€” from an initializer_list< _CharT >, allocator defaults
  • template<typename _Operation > void __resize_and_overwrite (size_type __n, _Operation __op) β€” non-standard version of resize_and_overwrite for C++11 and above, she's a little special like that 😌
  • const _Base & _M_base () const noexcept β€” const ref to _Base, noexcept
  • _Base & _M_base () noexcept β€” non-const ref to _Base, noexcept
  • template<typename _InputIterator > basic_string< _CharT, _Traits, _Alloc > & _M_replace_dispatch (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2, __false_type) β€” the _M_replace_dispatch internal, taking two iterators, two _InputIterators and a __false_type
  • template<typename _InIterator > _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, forward_iterator_tag) β€” _S_construct, returns _CharT *, takes a range, an allocator and a forward_iterator_tag

  • template<typename _InputIterator > basic_string & append (_InputIterator __first, _InputIterator __last) β€” append an iterator range
  • basic_string & append (const _CharT *__s) β€” append a _CharT pointer
  • basic_string & append (const _CharT *__s, size_type __n) β€” append __n characters from that pointer
  • template<typename _Tp > _If_sv< _Tp, basic_string & > append (const _Tp &__svt) β€” append a string_view ✨
  • template<typename _Tp > _If_sv< _Tp, basic_string & > append (const _Tp &__svt, size_type __pos, size_type __n=npos) β€” append a range of characters from a string_view, __n defaults to npos
  • basic_string & append (const basic_string &__str) β€” append a string to this string πŸ’–
  • basic_string & append (const basic_string &__str) β€” yes she's listed again with no description, we don't make the rules πŸ’…
  • basic_string & append (const basic_string &__str, size_type __pos, size_type __n) β€” no description on this one either, just vibes
  • basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos) β€” append a substring, __n defaults to npos
  • basic_string & append (initializer_list< _CharT > __l) β€” append an initializer_list of characters πŸŽ€
  • basic_string & append (size_type __n, _CharT __c) β€” append __n of character __c

  • template<typename _InputIterator > basic_string & assign (_InputIterator __first, _InputIterator __last) β€” assign from an iterator range
  • basic_string & assign (basic_string &&__str) noexcept(allocator_traits< _Alloc >::is_always_equal::value) β€” set value to contents of another string, move-style, noexcept depends on allocator_traits< _Alloc >::is_always_equal::value
  • basic_string & assign (basic_string &&__x) noexcept(noexcept(std::declval< _Base & >().assign(std::move(__x)))) β€” the other move assign, with that whole nested noexcept(noexcept(std::declval< _Base & >().assign(std::move(__x)))) situation
  • basic_string & assign (const _CharT *__s) β€” assign from a _CharT pointer
  • basic_string & assign (const _CharT *__s, size_type __n) β€” assign __n chars from a pointer
  • template<typename _Tp > _If_sv< _Tp, basic_string & > assign (const _Tp &__svt) β€” set value from a string_view
  • template<typename _Tp > _If_sv< _Tp, basic_string & > assign (const _Tp &__svt, size_type __pos, size_type __n=npos) β€” set value from a range of characters in a string_view, __n defaults to npos
  • basic_string & assign (const basic_string &__str) β€” set value to contents of another string
  • basic_string & assign (const basic_string &__str, size_type __pos, size_type __n) β€” no description, just the overload
  • basic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos) β€” set value to a substring of a string, __n defaults to npos
  • basic_string & assign (const basic_string &__x) β€” plain copy assign, no description listed
  • basic_string & assign (size_type __n, _CharT __c) β€” __n copies of __c
  • basic_string & assign (std::initializer_list< _CharT > __l) β€” assign from an initializer_list< _CharT >

  • reference at (size_type __n) β€” provides access to the data contained in the string πŸ‘‘
  • const_reference at (size_type __n) const β€” same deal, const flavor, provides access to the data contained in the string
  • reference back () β€” the back element, non-const
  • const_reference back () const noexcept β€” back element, const, noexcept
  • iterator begin () β€” iterator to the start
  • const_iterator begin () const noexcept β€” const iterator to the start, noexcept
  • const _CharT * c_str () const noexcept β€” the const _CharT *, noexcept, classic
  • size_type capacity () const noexcept β€” how much she can hold, noexcept
  • const_iterator cbegin () const noexcept β€” const begin, noexcept
  • const_iterator cend () const noexcept β€” const end, noexcept
  • void clear () β€” clears her out

  • int compare (const _CharT *__s) const noexcept β€” compare to a C string, noexcept, returns int
  • constexpr int compare (const _CharT *__s) const noexcept β€” the constexpr version of the C-string compare
  • template<typename _Tp > _If_sv< _Tp, int > compare (const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value) β€” compare to a string_view, noexcept powered by is_same< _Tp, __sv_type >::value
  • int compare (const basic_string &__str) const β€” compare to a string
  • int compare (const basic_string &__str) const β€” compare to a string, part two, the docs really said "again" πŸ’€
  • template<typename _Tp > _If_sv< _Tp, int > compare (size_type __pos, size_type __n, const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value) β€” compare to a string_view, with __pos and __n
  • 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 β€” same line again, she's an icon, she repeats herself ✨
  • int compare (size_type __pos, size_type __n1, const _CharT *__s) const β€” compare substring to a C string
  • 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 β€” constexpr substring-vs-C-string, note the __pos1/__n1 naming
  • constexpr int compare (size_type __pos1, size_type __n1, const _CharT *__s, size_type __n2) const β€” constexpr, plus __n2
  • template<typename _Tp > _If_sv< _Tp, int > compare (size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos) const noexcept(is_same< _Tp, __sv_type >::value) β€” compare to a string_view with __pos1, __n1, __pos2, and __n2=npos
  • 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, listed twice, periodt πŸ’…
  • size_type copy (_CharT *__s, size_type __n, size_type __pos=0) const β€” copy out __n chars into __s starting at __pos, which defaults to 0
  • const_reverse_iterator crbegin () const noexcept β€” const reverse begin, noexcept
  • const_reverse_iterator crend () const noexcept β€” const reverse end, noexcept
  • const _CharT * data () const noexcept β€” const pointer to the data, noexcept
  • _CharT * data () noexcept β€” return non-const pointer to contents πŸ”₯
  • bool empty () const noexcept β€” is she empty, noexcept, returns bool
  • iterator end () β€” iterator to the end
  • const_iterator end () const noexcept β€” const iterator to the end, noexcept

  • bool ends_with (_CharT __x) const noexcept β€” does she end with character __x
  • bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” ends with that basic_string_view< _CharT, _Traits >
  • bool ends_with (const _CharT *__x) const noexcept β€” ends with a _CharT pointer
  • iterator erase (__const_iterator __first, __const_iterator __last) β€” erase from __first to __last, note the __const_iterator spelling
  • iterator erase (__const_iterator __position) β€” erase at __position, __const_iterator again
  • iterator erase (iterator __first, iterator __last) β€” remove a range of characters
  • iterator erase (iterator __position) β€” remove one character
  • basic_string & erase (size_type __pos=0, size_type __n=_Base::npos) β€” the index version, __pos defaults to 0, __n defaults to _Base::npos

  • size_type find (_CharT __c, size_type __pos=0) const noexcept β€” find position of a character, __pos defaults to 0
  • size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find position of a C substring, needs __pos and __n
  • constexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” the constexpr version of that same C-substring find
  • size_type find (const _CharT *__s, size_type __pos=0) const noexcept β€” find position of a C string, __pos defaults to 0
  • constexpr size_type find (const _CharT *__s, size_type __pos=0) const noexcept β€” constexpr C-string find, __pos=0
  • template<typename _Tp > _If_sv< _Tp, size_type > find (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value) β€” find position of a string_view, noexcept(is_same< _Tp, __sv_type >::value)
  • 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, again, because of course πŸ¦‹
  • 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 (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find position of a character not in a C substring
  • constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” constexpr version of that one
  • size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexcept β€” find position of a character not in a C string, __pos=0
  • constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexcept β€” the constexpr twin, __pos=0
  • template<typename _Tp > _If_sv< _Tp, size_type > find_first_not_of (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value) β€” find position of a character not in a string_view
  • 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, duplicated, she said copy-paste slay πŸ’–

  • size_type find_first_of (_CharT __c, size_type __pos=0) const noexcept β€” find position of a character
  • size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” find position of a character of a C substring
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” constexpr flavor of that same one
  • size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept β€” find position of a character of a C string
  • constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept β€” constexpr, C string, __pos=0
  • template<typename _Tp > _If_sv< _Tp, size_type > find_first_of (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value) β€” find position of a character of a string_view
  • 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, and yes, she's here twice 🌈

  • size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexcept β€” find last position of a different character, __pos defaults to npos this time, not 0
  • 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 a C substring
  • constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” constexpr version of that last-not-of call πŸŽ€

okay so the overload parade continues 🎠 no skipping, bestie, we're reading every single one of these, hydrate first πŸ’§

  • constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos=_Base::npos) const noexcept β€” no blurb in the docs for this one, she's mysterious πŸ’…
  • 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. like, "where's the last char that's not in this C string" energy πŸ”
  • template<typename _Tp > _If_sv< _Tp, size_type > find_last_not_of (const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value) β€” same hunt, but the "not in here" thing is a string_view 🌸
  • 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 β€” and yeah it's listed twice in the docs, we don't ask questions πŸ’€
  • size_type find_last_of (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a character. last time this char shows up, go 🎯
  • 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, size_type __n) const noexcept β€” the constexpr twin, no blurb supplied ✨
  • constexpr size_type find_last_of (const _CharT *__s, size_type __pos=_Base::npos) const noexcept β€” also no blurb, just vibes πŸ¦‹
  • size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexcept β€” Find last position of a character of C string.
  • template<typename _Tp > _If_sv< _Tp, size_type > find_last_of (const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value) β€” Find last position of a character of string. but the string is a string_view 🫢
  • 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 β€” yes bestie, twice again, iconic behaviour honestly πŸ‘‘

  • reference front () β€” the docs give us nothing here 😭
  • const_reference front () const noexcept β€” const flavour, also un-blurbed
  • allocator_type get_allocator () const noexcept β€” Return copy of allocator used to construct this string. she remembers who made her πŸ₯Ή

the insert era, prepare yourself πŸ’…

  • iterator insert (__const_iterator __p, _CharT __c) β€” no description given 🌈
  • template<typename _InputIterator > iterator insert (__const_iterator __p, _InputIterator __first, _InputIterator __last) β€” also no description
  • iterator insert (const_iterator __p, size_type __n, _CharT __c) β€” nope, none here either
  • iterator insert (const_iterator __p, std::initializer_list< _CharT > __l) β€” still none πŸŽ€
  • iterator insert (iterator __p, _CharT __c) β€” Insert one character. one (1) lil guy 🐣
  • template<class _InputIterator > void insert (iterator __p, _InputIterator __beg, _InputIterator __end) β€” Insert a range of characters. whole squad, in they go 🚌
  • 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. spam that char, respectfully πŸ“
  • basic_string & insert (size_type __pos, const _CharT *__s) β€” undocumented, she's a mystery πŸ•΅οΈβ€β™€οΈ
  • basic_string & insert (size_type __pos, const _CharT *__s, size_type __n) β€” also no blurb
  • template<typename _Tp > _If_sv< _Tp, basic_string & > insert (size_type __pos, const _Tp &__svt) β€” Insert a string_view. ✨
  • basic_string & insert (size_type __pos, size_type __n, _CharT __c) β€” no blurb, moving on πŸƒβ€β™€οΈ
  • template<typename _Tp > _If_sv< _Tp, basic_string & > insert (size_type __pos1, const _Tp &__svt, size_type __pos2, size_type __n=npos) β€” Insert a string_view. again, but with a position inside the view too πŸͺ„
  • basic_string & insert (size_type __pos1, const basic_string &__str) β€” Insert value of a string.
  • basic_string & insert (size_type __pos1, const basic_string &__str) β€” listed twice, we move πŸ’€
  • basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n) β€” no blurb 🌸
  • basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos) β€” Insert a substring. a little slice of her 🍰

  • size_type length () const noexcept β€” Returns the number of characters in the string, not including any null-termination. the real count, no sneaky terminator πŸ‘€
  • size_type max_size () const noexcept β€” Returns the size() of the largest possible string. her absolute limit, respectfully πŸ”₯

  • operator __sv_type () const noexcept β€” Convert to a string_view. glow-up into a view πŸ¦‹

operator city, we're literally living here now πŸ™οΈ

  • basic_string & operator+= (_CharT __c) β€” no blurb πŸŽ€
  • basic_string & operator+= (const _CharT *__s) β€” none here either
  • template<typename _Tp > _If_sv< _Tp, basic_string & > operator+= (const _Tp &__svt) β€” Append a string_view. πŸ’–
  • basic_string & operator+= (const basic_string &__str) β€” Append a string to this string. girl math: string + string = longer string ✨
  • basic_string & operator+= (const basic_string &__str) β€” twice, slay πŸ’…
  • basic_string & operator+= (std::initializer_list< _CharT > __l) β€” no description 🌈
  • basic_string & operator= (_CharT __c) β€” undocumented
  • basic_string & operator= (basic_string &&)=default β€” also undocumented, note the =default 🫢
  • basic_string & operator= (const _CharT *__s) β€” still nothing
  • basic_string & operator= (const basic_string &)=default β€” =default again, that's all we know 😌
  • basic_string & operator= (std::initializer_list< _CharT > __l) β€” no blurb, bye πŸ‘‹
  • reference operator[] (size_type __pos) β€” no description given 🎯
  • const_reference operator[] (size_type __pos) const noexcept β€” const one, also no description

  • void pop_back () β€” undocumented πŸ’€
  • void push_back (_CharT __c) β€” also undocumented, cute little pair tho 🫢
  • reverse_iterator rbegin () β€” no blurb πŸŒ€
  • const_reverse_iterator rbegin () const noexcept β€” none
  • reverse_iterator rend () β€” none
  • const_reverse_iterator rend () const noexcept β€” none, ok moving πŸƒβ€β™€οΈ

the replace cinematic universe (this is the big one, stay with me) 🌌

  • template<typename _InputIterator > basic_string & replace (__const_iterator __i1, __const_iterator __i2, _InputIterator __j1, _InputIterator __j2) β€” undocumented πŸŽ€
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s) β€” none
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s, size_type __n) β€” none
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, const basic_string &__str) β€” none
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, size_type __n, _CharT __c) β€” none
  • basic_string & replace (__const_iterator __i1, __const_iterator __i2, std::initializer_list< _CharT > __l) β€” none 🌸
  • template<typename _Tp > _If_sv< _Tp, basic_string & > replace (const_iterator __i1, const_iterator __i2, const _Tp &__svt) β€” Replace range of characters with string_view. ✨
  • basic_string & replace (iterator __i1, iterator __i2, _CharT *__k1, _CharT *__k2) β€” no blurb, note these are non-const pointers πŸ‘€
  • template<class _InputIterator > basic_string & replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2) β€” Replace range of characters with range. trade a range for a range, fair trade 🀝
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__k1, const _CharT *__k2) β€” undocumented
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s) β€” Replace range of characters with C string.
  • basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s, size_type __n) β€” Replace range of characters with C substring.
  • basic_string & replace (iterator __i1, iterator __i2, const basic_string &__str) β€” Replace range of characters with string.
  • basic_string & replace (iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2) β€” no description
  • basic_string & replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l) β€” Replace range of characters with initializer_list.
  • basic_string & replace (iterator __i1, iterator __i2, iterator __k1, iterator __k2) β€” no blurb πŸŒ€
  • basic_string & replace (iterator __i1, iterator __i2, size_type __n, _CharT __c) β€” Replace range of characters with multiple characters. πŸ“
  • template<typename _Tp > _If_sv< _Tp, basic_string & > replace (size_type __pos, size_type __n, const _Tp &__svt) β€” Replace range of characters with string_view. ✨
  • basic_string & replace (size_type __pos, size_type __n, const basic_string &__str) β€” Replace characters with value from another string. borrowing her fit πŸ’–
  • basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s) β€” undocumented
  • basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) β€” undocumented
  • basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c) β€” undocumented 🌈
  • template<typename _Tp > _If_sv< _Tp, basic_string & > replace (size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos) β€” Replace range of characters with string_view. the deluxe version πŸŽ€
  • basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str) β€” no blurb
  • basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2) β€” no blurb
  • basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) β€” Replace characters with value from another string. 😌

  • void reserve () β€” Equivalent to shrink_to_fit(). yes, the zero-arg one does that, read it twice bestie πŸ‘€
  • void reserve (size_type __res_arg) β€” Attempt to preallocate enough memory for specified number of characters. grabbing seats before the squad arrives πŸͺ‘
  • void resize (size_type __n) β€” no description given πŸŽ€
  • void resize (size_type __n, _CharT __c) β€” also none
  • size_type rfind (_CharT __c, size_type __pos=npos) const noexcept β€” Find last position of a character. reverse search, go backwards babe πŸŒ€
  • constexpr size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const β€” undocumented ✨
  • size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexcept β€” Find last position of a C substring.
  • constexpr size_type rfind (const _CharT *__s, size_type __pos=_Base::npos) const β€” undocumented
  • size_type rfind (const _CharT *__s, size_type __pos=npos) const noexcept β€” Find last position of a C string.
  • template<typename _Tp > _If_sv< _Tp, size_type > rfind (const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value) β€” Find last position of a string_view. πŸ’…
  • size_type rfind (const basic_string &__str, size_type __pos=npos) const noexcept β€” Find last position of a string.
  • size_type rfind (const basic_string &__str, size_type __pos=npos) const noexcept β€” twice, of course πŸ’€
  • void shrink_to_fit () noexcept β€” no blurb 🌸
  • size_type size () const noexcept β€” Returns the number of characters in the string, not including any null-termination. same deal as length(), no terminator counted ⭐
  • bool starts_with (_CharT __x) const noexcept β€” undocumented
  • bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexcept β€” undocumented
  • bool starts_with (const _CharT *__x) const noexcept β€” undocumented, three lil starters with no notes πŸ™ˆ
  • basic_string substr (size_type __pos=0, size_type __n=_Base::npos) const β€” no description given πŸŽ€
  • void swap (basic_string &__s) noexcept(/*conditional */) β€” Swap contents with another string. trade fits, note the noexcept(/*conditional */) πŸ‘€
  • void swap (basic_string &__x) noexcept(/*conditional */) β€” no blurb, same noexcept(/*conditional */) energy πŸ”

πŸŽ€ Static Public Attributes πŸŽ€

  • static const size_type npos β€” Value returned by various member functions when they fail. the "nope, didn't find it" number πŸ’”

πŸ›‘οΈ Protected Member Functions πŸ›‘οΈ

  • constexpr void _M_swap (_Safe_container &__x) noexcept β€” no blurb in the docs, she's internal business 🀫

🫢 Friends 🫢

  • template<typename _ItT , typename _SeqT , typename _CatT > class ::__gnu_debug::_Safe_iterator β€” bestie privileges granted, no description given 🎟️

πŸ’– Detailed Description πŸ’–

template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
    typename _Allocator = std::allocator<_CharT>>
class __gnu_debug::basic_string< _CharT, _Traits, _Allocator >
"Class std::basic_string with safety/checking/debug instrumentation."

that's the whole pitch fr fr β€” it's std::basic_string but with safety/checking/debug instrumentation bolted on, and she's telling you that up front πŸ’…βœ¨

πŸ‘‘ Member Function Documentation πŸ‘‘

okay bestie, this is the big one β€” every member function, alphabetically, no skips. grab a snack πŸ“


πŸ’« __resize_and_overwrite

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]

Non-standard version of resize_and_overwrite for C++11 and above. yes it's got the double underscore, it's a vibe, don't @ me πŸ’…


πŸ”₯ append β€” the string_view edition

template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp >
_If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::append
    (const _Tp & __svt) [inline], [inherited]

Append a string_view.

  • Parameters
    • __svt β€” the object convertible to string_view that's getting appended 🫢
  • Returns β€” Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::append().


🌸 append β€” string_view but make it a slice

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

Append a range of characters from a string_view. little slice of string_view, iconic ✨

  • Parameters
    • __svt β€” the object convertible to string_view to be appended from.
    • __pos β€” the position in the string_view to append from.
    • __n β€” the number of characters to append from the string_view.
  • Returns β€” Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::append().


πŸ’– append β€” the classic string-on-string situation

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

Append a string to this string. the original, the blueprint πŸ‘‘

  • Parameters
    • __str β€” the string to append.
  • Returns β€” Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::size(), and std::size().

Referenced by all of these besties:

  • std::basic_string< _CharT, _Traits, _Alloc >::append()
  • std::basic_string< _CharT, _Traits, _Alloc >::append()
  • std::basic_string< _CharT, _Traits, _Alloc >::append()
  • std::basic_string< _CharT, _Traits, _Alloc >::append()
  • std::collate< _CharT >::do_transform()
  • std::basic_string< _CharT, _Traits, _Alloc >::operator+=()
  • std::basic_string< _CharT, _Traits, _Alloc >::operator+=()
  • std::basic_string< _CharT, _Traits, _Alloc >::operator+=()
  • std::basic_string< _CharT, _Traits, _Alloc >::operator+=()
  • std::operator>>()

(yes, four append()s and four operator+=()s β€” that's genuinely what it says, no cap 😭)


πŸ¦‹ append β€” substring core

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

Append a substring.

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

This function appends __n characters from __str starting at __pos to this string. If __n is is larger than the number of available characters in __str, the remainder of __str is appended. (the double "is is" is in the source, we respect the source in this house 🫑)

References std::size().


πŸŽ€ append β€” initializer_list era

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

Append an initializer_list of characters.

  • Parameters
    • __l β€” the initializer_list of characters to append.
  • Returns β€” Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::append().


🌈 assign β€” move it, move it

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

Set value to contents of another string.

  • Parameters
    • __str β€” source string to use.
  • Returns β€” Reference to this string.

This function sets this string to the exact contents of __str. __str is a valid, but unspecified string. ⚠️ like, it exists, but don't go assuming things about it, bestie.

References std::basic_string< _CharT, _Traits, _Alloc >::swap().


🧚 assign β€” from a string_view

template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp >
_If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::assign
    (const _Tp & __svt) [inline], [inherited]

Set value from a string_view.

  • Parameters
    • __svt β€” the source object convertible to string_view.
  • Returns β€” Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::assign().


πŸ’œ assign β€” string_view, sliced

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

Set value from a range of characters in a string_view.

  • Parameters
    • __svt β€” the source object convertible to string_view.
    • __pos β€” the position in the string_view to assign from.
    • __n β€” the number of characters to assign.
  • Returns β€” Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::assign().


🫢 assign β€” copy the whole thing

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

Set value to contents of another string.

  • Parameters
    • __str β€” source string to use.
  • Returns β€” Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::get_allocator().

Referenced by this whole friend group:

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

five assign()s and five operator=()s, i counted, they're all really there πŸ’€


⭐ assign β€” substring behavior

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

Set value to a substring of a string.

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

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

References std::basic_string< _CharT, _Traits, _Alloc >::assign().


πŸ“ at β€” the safe one (read/write)

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

Provides access to the data contained in the string.

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

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


🩡 at β€” the safe one (read-only)

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

Provides access to the data contained in the string.

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

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


🌸 back β€” last character, writable

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

Returns a read/write reference to the data at the last element of the string. the final girl of the string, she gets a reference πŸ’…


🧊 back β€” last character, but const

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

Returns a read-only (constant) reference to the data at the last element of the string. no touchy, just looky πŸ‘€


🎈 capacity β€” how much room she's got

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

Returns the total number of characters that the string can hold before needing to allocate more memory. it's giving "i have space for you in my life" energy ✨


πŸ† compare β€” versus a C string

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

Compare to a C string. the OG, the char*, showing up to the party.

  • Parameters
    • __s β€” C string to compare against.
  • Returns β€” Integer < 0, 0, or > 0.

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


πŸ¦‹ compare β€” versus a string_view

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
         typename _Allocator  = std::allocator<_CharT>>
template<typename _Tp >
_If_sv< _Tp, int > std::basic_string< _CharT, _Traits, _Alloc >::compare
    (const _Tp & __svt) const [inline], [noexcept]

Compare to a string_view.

  • Parameters
    • __svt β€” an object convertible to string_view to compare against.
  • Returns β€” Integer < 0, 0, or > 0.
  • Return value β€” oh and it returns an integer: < 0, 0, or > 0. ✨
Okay bestie, real talk: it 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. It figures out the effective length rlen of the strings to compare as the smallest of size() and str.size(). Then it compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first. πŸ’…

References: std::basic_string< _CharT, _Traits, _Alloc >::data(), std::min(), and std::basic_string< _CharT, _Traits, _Alloc >::size().


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

πŸ¦‹ Compare to a string (the version with the pretty defaults)

Literally the same energy as the one above, just with the default template args spelled out all cute. 🌸

  • __str β€” the string you're comparing against, bestie.

Returns: an integer < 0, 0, or > 0.

Same deal fr fr: 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. It determines the effective length rlen of the strings to compare as the smallest of size() and str.size(). Then it compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero it returns it; otherwise the shorter one is ordered first. No cap. 🫢

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

⭐ Compare to a string_view

Okay so this one's fab because it's [noexcept] β€” it's giving trustworthy main character energy. πŸ‘‘

  • __pos β€” a position in the string to start comparing from.
  • __n β€” the number of characters to compare.
  • __svt β€” an object convertible to string_view to compare against.

Returns: an integer < 0, 0, or > 0. πŸ’–


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

🌈 Compare substring to a string

Substring era!! We're not comparing the whole thing anymore, just a lil slice. πŸ“

  • __pos β€” index of first character of substring.
  • __n β€” number of characters in substring.
  • __str β€” string to compare against.

Returns: an integer < 0, 0, or > 0.

So what happens: 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. It determines 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 strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first. 😭 (in a slay way)

References: std::basic_string< _CharT, _Traits, _Alloc >::data(), std::min(), and std::basic_string< _CharT, _Traits, _Alloc >::size().


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

πŸŽ€ Compare substring to a string (again, but make it default-args)

Same function, same facts, just the _Traits / _Allocator defaults showing off. Obsessed. ✨

  • __pos β€” index of first character of substring.
  • __n β€” number of characters in substring.
  • __str β€” string to compare against.

Returns: an 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. It determines 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 strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first. πŸ’œ

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

🧚 Compare substring to a C string

A C string walked in, bestie. No std::basic_string wrapper, just vibes and a pointer. πŸ’€

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

Returns: an 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. It 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. Then it compares the two string by calling traits::compare(substring.data(),__s,rlen). If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first. 🌸

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

πŸ”₯ Compare substring against a character array

Now there's a __n2 in the mix and it's giving precise. Iconic behaviour. πŸ‘‘

  • __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: an 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. It determines 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 the comparison is nonzero it returns it, otherwise the shorter one is ordered first. πŸ¦‹
NB: s must have at least n2 characters, '\0' has no special meaning. 🚨 Like, for real for real, do not come in here with a short buffer and expect the null terminator to save you. It will not. It is not that girl. πŸ™ˆ

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

πŸ’– Compare to a string_view (the deluxe two-position edition)

Two positions, two lengths, one very [noexcept] queen. ⭐

  • __pos1 β€” a position in the string to start comparing from.
  • __n1 β€” the number of characters to compare.
  • __svt β€” an object convertible to string_view to compare against.
  • __pos2 β€” a position in the string_view to start comparing from.
  • __n2 β€” the number of characters to compare. It has a default: npos. πŸŽ€

Returns: an integer < 0, 0, or > 0.


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

πŸ‘‘ Compare substring to a substring

Substring vs substring. A whole collision of slices. This is the main event, bestie. πŸ”₯

  • __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. Defaults to npos. πŸ’œ

Returns: an 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. 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. ✨

References: std::basic_string< _CharT, _Traits, _Alloc >::data(), and std::min().


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

🌟 Compare substring to a substring (default-args remix)

Yeah okay this is the same thing again with the defaults written out. Slay, consistent queen. πŸ’…

  • __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. Defaults to npos.

Returns: an 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. 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. 🧚

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

🫢 data() β€” return non-const pointer to contents

This is a pointer to the character sequence held by the string. And here's the plot twist: modifying the characters in the sequence is allowed. 😳πŸ”₯ It's [noexcept] too, so she's chill about it.

Lowkey read that again β€” modifying the characters is allowed here. That's the whole point of this overload. You get a _CharT *, not a const _CharT *, so go off. But bestie, that also means if you write past the end it's on you β€” this page isn't handing out safety nets. πŸ’€

πŸ’– empty() β€” the instant β€œam I giving nothing?” check

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

Returns true if the string is empty. Equivalent to *this == ''. That’s it, bestie β€” the tiniest vibe check in the whole string class. πŸŽ€


βœ‚οΈ erase(iterator, iterator) β€” delete a whole little range

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. Very β€œclear the group chat from message 12 to 47” energy.

  • Parameters
    • __first β€” iterator referencing the first character to remove.
    • __last β€” iterator referencing the end of the range.
  • Returns β€” an iterator referencing the location of the first after removal.

Removes the characters in the range [first,last) from this string. The value of the string doesn’t change if an error is thrown. No cap, that safety bit matters. 🫢


πŸͺ„ erase(iterator) β€” one character, gone

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

Remove one character. Single-target elimination, main character style.

  • Parameters
    • __position β€” iterator referencing the character to remove.
  • Returns β€” iterator referencing the same location after removal.

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


πŸ”Ž find(_CharT, size_type) β€” where’s my character at?

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

Find position of a character. The classic β€œhave you seen her?” search.

  • Parameters
    • __c β€” character to locate.
    • __pos β€” index of character to search from (default 0).
  • Returns β€” index of first occurrence.

Starting from __pos, searches forward for __c within this string. If found, returns the index where it was found. If not found, returns npos. Soft launch: npos means she’s not here. 😭


🧡 find(const _CharT*, size_type, size_type) β€” C substring hunt

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

Find position of a C substring. You’re not searching the whole C string, just the first __n characters of it. Selective.

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


πŸŽ€ find(const _CharT*, size_type) β€” C string hunt

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

Find position of a C string. Full C-string search, no __n little shortcut.

  • 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. Slay. πŸ¦‹


🌸 find(const _Tp&, size_type) β€” string_view find

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> template<typename _Tp >
    _If_sv< _Tp, size_type > std::basic_string< _CharT, _Traits, _Alloc
    >::find (const _Tp & __svt, size_type __pos = 0) const [inline],
    [noexcept]

Find position of a string_view. This one is for the object that’s convertible to string_view. Fancy but lowkey.

  • Parameters
    • __svt β€” the object convertible to string_view to locate.
    • __pos β€” index of character to search from (default 0).
  • Returns β€” index of start of first occurrence.

That’s the whole note here β€” no extra lore in this entry. πŸŽ€


πŸ’œ find(const basic_string&, size_type) β€” inherited string find

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

Find position of a string. The [inherited] tag is right there, bestie.

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

  • References β€” std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::find(), and std::basic_string< _CharT, _Traits, _Alloc >::size().

🌈 find(const basic_string&, size_type) β€” the allocator-name twin

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

Find position of a string. Same β€œwhere is she?” mission, but the parameter is spelled with _Allocator in the signature. Character-for-character twin behavior, no invented extras.

  • 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(_CharT, size_type) β€” find literally anything else

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

Find position of a different character. The anti-__c search. Avoid this character at all costs.

  • 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. It’s giving β€œnot like other girls” but in index form. πŸ’€


πŸ“ find_first_not_of(const _CharT*, size_type, size_type) β€” avoid these C substring chars

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> 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 [noexcept]

Find position of a character not in C substring. You’re avoiding only the first __n characters of __s, not the whole thing. Very specific.

  • 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*, size_type) β€” avoid this C string

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

Find position of a character not in C string. Full __s avoid list, no __n limits.

  • 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 _Tp&, size_type) β€” avoid these string_view chars

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

Find position of a character not in a string_view. Same avoid-list energy, but the object is convertible to string_view.

  • Parameters
    • __svt β€” an object convertible to string_view containing characters to avoid.
    • __pos β€” index of character to search from (default 0).
  • Returns β€” index of first occurrence.

No extra prose in this entry β€” just the parameters and the return. Keep it moving, bestie. πŸ’…


πŸ’€ find_first_not_of(const basic_string&, size_type) β€” inherited avoid-string

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

Find position of a character not in string. Avoid the characters that live in __str. So real.

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

  • References β€” std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
  • Referenced by β€” std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of(), std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of(), and std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of().

That’s three identical find_first_not_of() references in the original, and we’re keeping all three. No erasing the receipts. 🫢


🌟 find_first_not_of(const basic_string&, size_type) β€” allocator-name twin

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> size_type
    std::basic_string< _CharT, _Traits, _Alloc >::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. Same mission, with _Allocator showing up in the parameter type.

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

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


πŸ”₯ find_first_of(_CharT, size_type) β€” first matching character

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

Find position of a character. It’s literally the β€œdo I have this one?” check.

  • Parameters
    • __c β€” character to locate.
    • __pos β€” index of character to search from (default 0).
  • Returns β€” index of first occurrence.

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

Note: equivalent to find(__c, __pos).

Iconic shortcut behavior, no notes missed. πŸŽ€


⭐ find_first_of(const _CharT*, size_type, size_type) β€” matching chars from a C substring

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> 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 [noexcept]

Find position of a character of C substring. You’re looking for any character from the first __n characters of __s.

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

okay so picking right back up where we left off β€” __pos is your starting point, and you're scrolling forward through the string looking for any one of the first __n characters of __s just vibing in there. Found one? slay, you get the index of where it was. Not found? npos, bestie. Always npos. 😭


✨ find_first_of (C string version) ✨

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

Find position of a character of C string. fr fr that's the whole gig πŸ’…

Parameters

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

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the characters of __s within this string. Found it? You get the index where it was found. Didn't find it? npos. That's it, that's the whole story πŸ¦‹


✨ find_first_of (string_view version) ✨

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> template<typename _Tp >
    _If_sv< _Tp, size_type > std::basic_string< _CharT, _Traits, _Alloc
    >::find_first_of (const _Tp & __svt, size_type __pos = 0) const
    [inline],  [noexcept]

Find position of a character of a string_view. the string_view girly pop version πŸŽ€

Parameters

  • __svt β€” An object convertible to string_view containing characters to locate.
  • __pos β€” Index of character to search from (default 0).

Returns

Index of first occurrence.


✨ find_first_of (basic_string version, the [inherited] one) ✨

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

Find position of a character of string. yes queen, another one πŸ‘‘

Parameters

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

Returns

Index of first occurrence.

Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos. same energy, different parameter πŸ’–

References std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::find_first_of(), and std::basic_string< _CharT, _Traits, _Alloc >::size().

Referenced by std::basic_string< _CharT, _Traits, _Alloc >::find_first_of(), std::basic_string< _CharT, _Traits, _Alloc >::find_first_of(), and std::basic_string< _CharT, _Traits, _Alloc >::find_first_of(). (yes it's listing itself three times, no I will not be explaining, it's giving recursion energy πŸ’€)


✨ find_first_of (basic_string version, _Allocator flavored) ✨

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

Find position of a character of string. notice the template param says _Allocator in the argument and _Alloc in the class β€” that is NOT a typo, do not come for me 🌸

Parameters

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

Returns

Index of first occurrence.

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


✨ find_last_not_of (single character version) ✨

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

Find last position of a different character. the "not like the other girls" of string search πŸ’…

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. Found one that isn't __c? You get its index. Found nothing? npos. she's picky, she's selective, she's iconic ✨


✨ find_last_not_of (C substring version) ✨

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> 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 [noexcept]

Find last position of a character not in C substring.

Parameters

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

Returns

Index of last occurrence.

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


✨ find_last_not_of (C string version) ✨

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

Find last position of a character not in C string.

Parameters

  • __s β€” 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. Found it? index. Not found? npos. no cap πŸ’―


✨ find_last_not_of (string_view version) ✨

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

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

Parameters

  • __svt β€” An object convertible to string_view containing characters to avoid.
  • __pos β€” Index of character to search back from (default end).

Returns

Index of last occurrence.


✨ find_last_not_of (basic_string version, the [inherited] one) ✨

template<typename _CharT , typename _Traits , typename _Alloc > size_type
    std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of (const
    basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = npos)
    const [inline],  [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. πŸ’œ

References std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(), and std::basic_string< _CharT, _Traits, _Alloc >::size().

Referenced by std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(), std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(), and std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(). (three times. again. it's a whole thing. πŸ’€)


✨ find_last_not_of (basic_string version, _Allocator flavored) ✨

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


✨ find_last_of (single character version) ✨

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

Find last position of a character. the "yes actually I am looking for you" counterpart to the last one 😌

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 version) ✨

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> 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 [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 string version) ✨

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

Find last position of a character of C string. πŸ‘‘

Parameters

  • __s β€” C string containing characters to locate.
  • __pos β€” Index of 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. literally the same deal as always, just backwards πŸ’–


✨ find_last_of (string_view version) ✨

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> template<typename _Tp >
    _If_sv< _Tp, size_type > std::basic_string< _CharT, _Traits, _Alloc
    >::find_last_of (const _Tp & __svt, size_type __pos = npos) const
    [inline],  [noexcept]

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

Parameters

  • __svt β€” An object convertible to string_view containing characters to locate.
  • __pos β€” Index of character to search back from (default end).

Returns

Index of last occurrence.


✨ find_last_of (basic_string version, the [inherited] one) ✨

template<typename _CharT , typename _Traits , typename _Alloc > size_type
    std::basic_string< _CharT, _Traits, _Alloc >::find_last_of (const
    basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = npos)
    const [inline],  [noexcept],  [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 goes backward looking for any one of the characters in __str that also lives in this string. Found it? You get the index where it's chillin'. Not found? npos. That's it, that's the vibe. πŸ’…

References std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::find_last_of(), and std::basic_string< _CharT, _Traits, _Alloc >::size().

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


🌸 find_last_of (the string version, bestie)

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> size_type
    std::basic_string< _CharT, _Traits, _Alloc >::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. Like, the last one, periodt.

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. No cap.


πŸ¦‹ front (the glow-up version, read/write)

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

Returns a read/write reference to the data at the first element of the string. You can literally touch it. Main character energy at index zero. ✨


πŸŽ€ front (const version, look don't touch)

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> const_reference
    std::basic_string< _CharT, _Traits, _Alloc >::front () const [inline],
    [noexcept]

Returns a read-only (constant) reference to the data at the first element of the string. Admire from a distance, bestie. πŸ™ˆ


πŸ’œ get_allocator

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> allocator_type
    std::basic_string< _CharT, _Traits, _Alloc >::get_allocator () const
    [inline],  [noexcept]

Return copy of allocator used to construct this string. It's giving "here's the receipts of who built me." 🧾


πŸ”₯ insert β€” single character

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

Insert one character. Just the one. A little guy. πŸ“

Parameters

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

Returns

Iterator referencing newly inserted char.

Exceptions

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

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


🌈 insert β€” a whole range, we love a range

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. Bring the whole friend group. πŸ’–

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.

References std::basic_string< _CharT, _Traits, _Alloc >::replace().


🧚 insert β€” initializer_list 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().

References std::basic_string< _CharT, _Traits, _Alloc >::insert().


⭐ insert β€” __n copies of one char

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. Copy-paste energy but, like, on purpose. 🫢

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.

References std::basic_string< _CharT, _Traits, _Alloc >::replace().

Referenced by std::basic_string< _CharT, _Traits, _Alloc >::insert(), std::basic_string< _CharT, _Traits, _Alloc >::insert(), std::basic_string< _CharT, _Traits, _Alloc >::insert(), std::basic_string< _CharT, _Traits, _Alloc >::insert(), and std::basic_string< _CharT, _Traits, _Alloc >::insert(). (Yes, five of them. It's a whole family reunion. 😭)


πŸŽ€ insert β€” string_view, the pos version

template<typename _CharT , typename _Traits , typename _Alloc >
    template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string<
    _CharT, _Traits, _Alloc >::insert (size_type __pos, const _Tp & __svt)
    [inline],  [inherited]

Insert a string_view. Views are lowkey superior, ngl.

Parameters

  • __pos β€” Position in string to insert at.
  • __svt β€” The object convertible to string_view to insert.

Returns

Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::insert().


🌸 insert β€” string_view, the pos + pos + n version

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

Insert a string_view. But like, a slice of one. Fancy.

Parameters

  • __pos1 β€” Position in string to insert at.
  • __svt β€” The object convertible to string_view to insert from.
  • __pos2 β€” Position in string_view to insert from.
  • __n β€” The number of characters to insert.

Returns

Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::replace().


πŸ’… insert β€” whole string, no thoughts

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

Insert value of a string.

Parameters

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

Returns

Reference to this string.

Exceptions

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

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

References std::basic_string< _CharT, _Traits, _Alloc >::insert(), and std::basic_string< _CharT, _Traits, _Alloc >::size().


πŸ¦‹ insert β€” substring, we're being selective

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

Insert a substring. Only part of the group chat gets invited.

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. Bestie, it's safe β€” mess it up and your string is untouched. πŸ’€

References std::basic_string< _CharT, _Traits, _Alloc >::insert().


πŸŽ€ length

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

Returns the number of characters in the string, not including any null-termination. So the little \0 gremlin at the end doesn't count, okay? πŸ™…β€β™€οΈ


πŸ’œ max_size

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

Returns the size() of the largest possible string. The absolute limit. The final boss. πŸ‘‘


🌈 operator __sv_type β€” the string_view conversion

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

Convert to a string_view. Glow-down into a lighter, cuter form. πŸ¦‹

Returns

A string_view.

References std::basic_string< _CharT, _Traits, _Alloc >::data(), and std::basic_string< _CharT, _Traits, _Alloc >::size().


πŸ“ operator+= β€” appending a string_view

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

Append a string_view. Add it to the end, no big deal.

Parameters

  • __svt β€” The object convertible to string_view to be appended.

Returns

Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::append().


πŸ’– operator+= β€” appending a whole string

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

Append a string to this string. Two strings become one. Soulmate behaviour, fr fr. 🫢

Parameters

  • __str β€” The string to append.

Returns

Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::append().


🧚 replace β€” iterator pair + string_view

template<typename _CharT , typename _Traits , typename _Alloc >
    template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string<
    _CharT, _Traits, _Alloc >::replace (const_iterator __i1, const_iterator
    __i2, const _Tp & __svt) [inline],  [inherited]

Replace range of characters with string_view. Out with the old, in with the view. ✨

Parameters

  • __i1 β€” An iterator referencing the start position to replace at.
  • __i2 β€” An iterator referencing the end position for the replace.
  • __svt β€” The object convertible to string_view to insert from.

Returns

Reference to this string.

References std::basic_string< _CharT, _Traits, _Alloc >::begin(), and std::basic_string< _CharT, _Traits, _Alloc >::replace().

🌸 replace() β€” the glow-up function, 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]

Okay bestie, this one is literally "replace a range of characters with a range" ✨ β€” swapping out a chunk for a whole other chunk, no cap.

  • Parameters
    • __i1 β€” iterator pointing at the start of the range you're replacing.
    • __i2 β€” iterator pointing at the end of the range you're replacing.
    • __k1 β€” iterator pointing at the start of the range you're inserting.
    • __k2 β€” iterator pointing at the end of the range you're inserting.
  • Returns β€” a reference to this string 🫢
  • Exceptions β€” std::length_error if the new length exceeds max_size().

So what actually happens: the characters in the range [__i1,__i2) get removed. Then, in place, the characters in [__k1,__k2) get inserted. If the resulting length blows past max_size(), length_error is thrown. And the bestie-safe part: the value of the string doesn't change if an error is thrown πŸ’–. Nothing half-done, nothing messy.


πŸŽ€ replace() β€” same energy, but with 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) [inline], [inherited]

Replace a range of characters with a C string, iconic behaviour only.

  • Parameters
    • __i1 β€” iterator referencing start of range to replace.
    • __i2 β€” iterator referencing end of range to replace.
    • __s β€” the C string value to insert.
  • Returns β€” reference to this string.
  • Exceptions β€” std::length_error if new length exceeds max_size().

Removes the characters in [__i1,__i2), and in place the characters of __s get inserted. Length overflow β†’ length_error. Error thrown β†’ string value untouched. Periodt.

References: std::basic_string< _CharT, _Traits, _Alloc >::replace().


πŸ¦‹ replace() β€” the C substring one (now with a length count)

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]

"Replace range of characters with C substring" β€” yes, that's the whole vibe.

  • 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 [__i1,__i2), then in place the first __n characters of __s get inserted. If the result is longer than max_size(), length_error gets yeeted at you. And once again: value unchanged if an error is thrown πŸ™ˆ.

References: std::basic_string< _CharT, _Traits, _Alloc >::replace().


πŸ’œ replace() β€” swapping in another basic_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 β€” simple, clean, slay.

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

Characters in [__i1,__i2) are gone, the value of __str slides in instead, and if that makes the length exceed max_size() you get a length_error. Error β†’ string value stays exactly as it was, no notes.

References: std::basic_string< _CharT, _Traits, _Alloc >::replace(), and std::basic_string< _CharT, _Traits, _Alloc >::size().


πŸ“ replace() β€” the initializer_list cutie

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 β€” feeding it a lil squad of chars πŸ§šβ€β™€οΈ

  • 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 [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. 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.

πŸ™ˆ okay real talk β€” yes, this overload's description literally mentions [__k1,__k2) even though this signature has no __k1/__k2 anywhere. That's the docs' own copy-paste moment, so we're reporting it exactly as written, no edits, no gaslighting. Keeping it 100 with the source πŸ’€

References: std::basic_string< _CharT, _Traits, _Alloc >::replace().


πŸ”₯ replace() β€” n copies of one character, the fill situation

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 ✨

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

Characters in [__i1,__i2) get removed, and in their place you get __n copies of __c. Length goes over max_size() β†’ length_error. Error thrown β†’ value stays put, untouched, immaculate.


🌈 replace() β€” the string_view era (_If_sv, position + count version)

template<typename _CharT , typename _Traits , typename _Alloc >
    template<typename _Tp >
_If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::replace
    (size_type __pos, size_type __n, const _Tp & __svt) [inline], [inherited]

Replace range of characters with string_view β€” flexible bestie energy πŸ¦‹

  • Parameters
    • __pos β€” the position to replace at.
    • __n β€” the number of characters to replace.
    • __svt β€” the object convertible to string_view to insert.
  • Returns β€” reference to this string.

References: std::basic_string< _CharT, _Traits, _Alloc >::replace().


πŸ‘‘ replace() β€” position-based, string in, range out

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

Replace characters with value from another string β€” the classic ✨

  • 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, and in place the value of __str is inserted. If __pos is beyond the end of the string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. And the value of the string doesn't change if an error is thrown πŸ’–.

References: std::basic_string< _CharT, _Traits, _Alloc >::replace(), and std::basic_string< _CharT, _Traits, _Alloc >::size().

Referenced by β€” okay this list is long, buckle up 🎒: std::basic_string< _CharT, _Traits, _Alloc >::append(), std::basic_string< _CharT, _Traits, _Alloc >::assign(), std::basic_string< _CharT, _Traits, _Alloc >::insert() (three times), and then std::basic_string< _CharT, _Traits, _Alloc >::replace() a full ten more times. Yeah. Ten. That's the whole overload set calling back home. Main character energy fr fr.


🫢 replace() β€” string_view again, but with a source offset this time

template<typename _CharT , typename _Traits , typename _Alloc >
    template<typename _Tp >
_If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::replace
    (size_type __pos1, size_type __n1, const _Tp & __svt, size_type __pos2,
     size_type __n2 = npos) [inline], [inherited]

Replace range of characters with string_view β€” but picky about where in the view you start πŸ‘€

  • Parameters
    • __pos1 β€” the position to replace at.
    • __n1 β€” the number of characters to replace.
    • __svt β€” the object convertible to string_view to insert from.
    • __pos2 β€” the position in the string_view to insert from.
    • __n2 β€” the number of characters to insert.
  • Returns β€” reference to this string.

References: std::basic_string< _CharT, _Traits, _Alloc >::replace().


πŸ’€ replace() β€” two positions, two counts, maximum drama

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

Replace characters with value from another string β€” the fully-specified version, iykyk 🌸

  • 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, and in place the value of __str is inserted. If __pos is beyond the end of the 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 πŸ™ˆ.

References: std::basic_string< _CharT, _Traits, _Alloc >::replace().


πŸŽ€ reserve() β€” the no-arg one, and it's a little plot twist

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

Equivalent to shrink_to_fit().

That's it. That's the whole description. Not me expecting it to reserve anything 😭 β€” no cap, it shrinks. Read it twice, bestie.


⭐ reserve(size_type __res_arg) β€” this one actually reserves

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

Attempt to preallocate enough memory for specified number of characters β€” the responsible, forward-thinking icon behaviour πŸ‘‘

  • Parameters
    • __res_arg β€” number of characters required.
  • Exceptions β€” std::length_error if __res_arg exceeds max_size().

So this function attempts to reserve enough memory for the string to hold the specified number of characters. If the number you asked for is more than max_size(), length_error is thrown.

The advantage, and this is genuinely the good part: if optimal code is a necessity and you, the user, can determine the string length that will be required, you can reserve the memory in advance β€” and thus prevent a possible reallocation of memory and copying of string data. Chef's kiss. No more surprise realloc mid-loop. We love a plan πŸ’–


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

find the last position of a character, bestie ✨ β€” this overload is on the hunt for one single character, and it goes backwards from __pos.

Parameters

  • __c β€” the character you're locating πŸ‘€
  • __pos β€” the index of the character to search back from (defaults to the end, obvs)

Returns

The index of the last occurrence. That's it, that's the tea.

Starting from __pos, it searches backward for __c within this string. Found it? Slay, you get the index where it was found. Not found? npos. Periodt. πŸ’…


template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> basic_string< _CharT,
    _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits, _Alloc
    >::rfind (const _CharT * __s, size_type __pos, size_type __n) const
    [noexcept]

find the last position of a C substring πŸ¦‹ β€” this one's like the character version but it's matching a whole little crew of __n characters.

Parameters

  • __s β€” the C string to locate 🎯
  • __pos β€” the index of the character to search back from
  • __n β€” how many characters from s to search for (yes, the parameter doc literally says s, we don't make the rules 🫠)

Returns

The index of the start of the last occurrence, gorgeous. πŸ‘‘

Starting from __pos, it searches backward 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. No cap. πŸ’€


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

find the last position of a C string 🌸 β€” the whole-C-string edition, [inline] and [noexcept] because she's efficient and she does not throw.

Parameters

  • __s β€” the C string to locate πŸ“
  • __pos β€” the index of the character to start the search at (defaults to the end, iykyk)

Returns

The index of the start of the last occurrence. πŸ’–

Starting from __pos, it searches backward for the value of __s within this string. Found it? Here's the index where it begins. Not found? npos. Same energy as always, fr fr.


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

find the last position of a string_view 🧚 β€” template-on-template, she's fancy like that. Also [inline] and [noexcept].

Parameters

  • __svt β€” the object convertible to string_view to locate 🌈
  • __pos β€” the index of the character to search back from (default end, bestie)

Returns

The index of the start of the last occurrence. πŸŽ€ (That's all the docs give us on this one β€” no extra description, so I'm not gonna invent one, ngl.)


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

find the last position of a string ⭐ β€” note the [inherited] tag, she got this from the base class and she's thriving.

Parameters

  • __str β€” the string to locate πŸ”₯
  • __pos β€” the index of the character to search back from (default end)

Returns

The index of the start of the last occurrence. πŸ’œ

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

References std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::rfind(), and std::basic_string< _CharT, _Traits, _Alloc >::size().

Referenced by std::basic_string< _CharT, _Traits, _Alloc >::find_last_of(), std::basic_string< _CharT, _Traits, _Alloc >::rfind(), std::basic_string< _CharT, _Traits, _Alloc >::rfind(), and std::basic_string< _CharT, _Traits, _Alloc >::rfind(). (Yes, rfind references rfind β€” it's giving recursion energy, we love to see it πŸ™ˆ)


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

find the last position of a string πŸ¦‹ β€” the non-inherited twin, template params spelled the long way with _Allocator. [inline], [noexcept], iconic.

Parameters

  • __str β€” the string to locate πŸ‘‘
  • __pos β€” the index of the character to search back from (default end)

Returns

The index of the start of the last occurrence. ✨

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


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

size() β€” returns the number of characters in the string, not including any null-termination. Luv, the null terminator is not being counted, it's not invited to the party. πŸŽ‰ [inline], [noexcept], tiny but mighty.


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

swap contents with another string 🌿 β€” [noexcept], [inherited], and honestly kind of a flex.

Parameters

  • __s β€” the string to swap with 🫢

Exchanges the contents of this string with that of __s in constant time. Constant time!! She's not copying anything, she's just swapping the vibes. 😭πŸ”₯

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


🫢 MEMBER DATA DOCUMENTATION 🫢

template<typename _CharT , typename _Traits  = std::char_traits<_CharT>,
    typename _Allocator  = std::allocator<_CharT>> const basic_string<
    _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
    _Alloc >::npos [static]
  • npos [static] β€” the value returned by various member functions when they fail. πŸ’€ She's the "it didn't work out babe" constant, the static queen of not-found, and we respect her.

πŸ’– AUTHOR πŸ’–

Generated automatically by Doxygen for libstdc++ from the source code. Not a human, just a little robot doing its absolute best. πŸ€–βœ¨

Ok bestie, that's the whole page, start to finish β€” every flag, every param, every npos, all of it. πŸŽ€

And for the sign-off: this lil' masterpiece is a libstdc++ man page, and the footer lexes as libst__gnu_debug::ba...s, _Allocator >(3cxx) (yes the name got absolutely bodied by truncation, she's mysterious now πŸ™ˆ). Take care of her, cite the version, and go write some strings. Mwah! πŸ’…πŸ’œπŸ¦‹

πŸ“¦ where this page comes from