__GNU_DEBUG::BASIC_STRING(3)
π __gnu_debug::basic_string< _CharT, _Traits, _Allocator >(3) π
okay so this page is from the Library Functions Manual, and it's giving very specific debug-string energy. bestie, we're talking about a whole class here, so let's get into it. π«Ά
β¨ NAME β¨
__gnu_debug::basic_string< _CharT, _Traits, _Allocator > β Class std::basic_string with safety/checking/debug instrumentation. literally that's the whole name, no cap. π
πΈ SYNOPSIS πΈ
first things first, you gotta pull it in like this:
#include <string>
and bestie, it inherits from __gnu_debug::_Safe_container< _SafeContainer, _Alloc, _SafeBase, _IsCxx11AllocatorAware >, and from std::basic_string< _CharT, _Traits, _Alloc >. periodt. π
π Public Types π
the type lineup is iconic, fr fr. every single one, exactly as written:
typedef _Allocator allocator_type
typedef __gnu_debug::_Safe_iterator< typename _Base::const_iterator, basic_string > const_iterator
typedef _Base::const_pointer const_pointer
typedef _Base::const_reference const_reference
typedef std::reverse_iterator< const_iterator > const_reverse_iterator
typedef _Base::difference_type difference_type
typedef __gnu_debug::_Safe_iterator< typename _Base::iterator, basic_string > iterator
typedef _Base::pointer pointer
typedef _Base::reference reference
typedef std::reverse_iterator< iterator > reverse_iterator
typedef _Base::size_type size_type
typedef _Traits traits_type
typedef _Traits::char_type value_type
no skips, no shortcuts, all the typedefs are present and accounted for. π¦β¨
β¨ Public Member Functions β¨
okay bestie buckle UP π this is the whole member-function roster of basic_string and it is long, so grab a strawberry matcha and let's go. Every single overload is listed, no cap. π«Ά
basic_string (_Base &&__base) noexceptβ moves a_Basein, no throwing allowed, she's calm πtemplate<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> basic_string (_InputIterator __begin, _InputIterator __end, const _Allocator &__a=_Allocator())β builds from an iterator range, and that_RequireInputIteris basically a bouncer checking ur iterators are legit β¨basic_string (basic_string &&)=defaultβ move constructor, defaulted, iconic πbasic_string (basic_string &&__s, const _Allocator &__a) noexcept(std::is_nothrow_constructible< _Base, _Base, const _Allocator & >::value)β move + allocator, and it only promisesnoexceptif the base says it can π¦basic_string (const _Allocator &__a) noexceptβ allocator-only ctor, empty string energy, no throw πbasic_string (const _Base &__base)β copies a_Basein πΈbasic_string (const _CharT *__s, const _Allocator &__a=_Allocator())β from a C string, allocator optional πbasic_string (const _CharT *__s, size_type __n, const _Allocator &__a=_Allocator())β from a C string but only__nof it, precise queen πbasic_string (const basic_string &)=defaultβ copy constructor, defaulted, the classic πbasic_string (const basic_string &__s, const _Allocator &__a)β copy but swap in ur own allocator πbasic_string (const basic_string &__str, size_type __pos, size_type __n=_Base::npos, const _Allocator &__a=_Allocator())β copy a slice of another string starting at__posβbasic_string (size_type __n, _CharT __c, const _Allocator &__a=_Allocator())β__ncopies of character__c, the filler arc πbasic_string (std::initializer_list< _CharT > __l, const _Allocator &__a=_Allocator())β straight from aninitializer_list, curly-brace girlies rise πtemplate<typename _Operation> constexpr void __resize_and_overwrite (size_type __n, _Operation __op)β Non-standard version ofresize_and_overwritefor C++11 and above. π§template<typename _Operation> void __resize_and_overwrite (size_type __n, _Operation __op)β Non-standard version ofresize_and_overwritefor C++11 and above. yes there are two of them, don't @ me π
const _Base & _M_base () const noexceptβ hands u the underlying base, const edition π_Base & _M_base () noexceptβ same but non-const, go wild πtemplate<typename _InputIterator> basic_string< _CharT, _Traits, _Alloc > & _M_replace_dispatch (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2, __false_type)β internal dispatch machinery for the replace family,__false_typetagging along for the ride βοΈtemplate<typename _InIterator> _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, forward_iterator_tag)β internal construction helper that knows it's got aforward_iterator_tagπ«
template<typename _InputIterator> basic_string & append (_InputIterator __first, _InputIterator __last)β appends an iterator range πΈbasic_string & append (const _CharT *__s)β appends a C string πbasic_string & append (const _CharT *__s, size_type __n)β appends__nchars of a C string πbasic_string & append (const basic_string &__str)β appends another string, the og move πbasic_string & append (const basic_string &__str, size_type __pos, size_type __n)β appends a slice of another string π¦basic_string & append (size_type __n, _CharT __c)β appends__ncopies of a char β¨constexpr basic_string & append (const _CharT *__s, size_type __n)β Append a C substring. π₯constexpr basic_string & append (const basic_string &__str)β Append a string to this string. πconstexpr basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos)β Append a substring. πconstexpr basic_string & append (initializer_list< _CharT > __l)β Append aninitializer_listof characters. πconstexpr basic_string & append (size_type __n, _CharT __c)β Append multiple characters. β
template<typename _InputIterator> basic_string & assign (_InputIterator __first, _InputIterator __last)β replaces contents with an iterator range πbasic_string & assign (basic_string &&__x) noexcept(noexcept(std::declval< _Base & >().assign(std::move(__x))))β move-assign, and thenoexceptis literally mirroring whatever the base does πbasic_string & assign (const _CharT *__s)β assign from a C string πbasic_string & assign (const _CharT *__s, size_type __n)β assign from__nchars of a C string πΈbasic_string & assign (const basic_string &__str, size_type __pos, size_type __n)β assign from a slice of another string π¦basic_string & assign (const basic_string &__x)β assign from another string πbasic_string & assign (size_type __n, _CharT __c)β assign__ncopies of a char β¨basic_string & assign (std::initializer_list< _CharT > __l)β assign from aninitializer_listπconstexpr basic_string & assign (basic_string &&__str) noexcept(_Alloc_traits::_S_nothrow_move())β Set value to contents of another string. πconstexpr basic_string & assign (const _CharT *__s, size_type __n)β Set value to a C substring. πconstexpr basic_string & assign (const basic_string &__str)β Set value to contents of another string. πconstexpr basic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos)β Set value to a substring of a string. πconstexpr basic_string & assign (size_type __n, _CharT __c)β Set value to multiple characters. β
constexpr reference at (size_type __n)β Provides access to the data contained in the string. πreference at (size_type __n)β Provides access to the data contained in the string. (again! different overload bestie) πconstexpr const_reference at (size_type __n) constβ Provides access to the data contained in the string. πconst_reference at (size_type __n) constβ Provides access to the data contained in the string. πconstexpr reference at (size_type __n)β Provides access to the data contained in the string. πΈconstexpr const_reference at (size_type __n) constβ Provides access to the data contained in the string. π¦
constexpr const_reference back () const noexceptβ last character, but read-only and unbothered πconstexpr reference back () noexceptβ last character, editable πiterator begin ()β iterator to the front, no throw guarantee, she's just vibing β¨const_iterator begin () const noexceptβ const iterator to the front πconst _CharT * c_str () const noexceptβ null-terminated C string pointer, the classic π«Άconstexpr size_type capacity () const noexceptβ how much she can hold before reallocating πͺconst_iterator cbegin () const noexceptβ const begin, the c-prefix girlies get it πconst_iterator cend () const noexceptβ const end, matching set πvoid clear ()β wipe it, bye πconstexpr int compare (const _CharT *__s) const noexceptβ compare against a C string, no throw πconstexpr int compare (const basic_string &__str) constβ Compare to a string. π¦constexpr int compare (size_type __pos, size_type __n, const basic_string &__str) constβ Compare substring to a string. πΈint compare (size_type __pos, size_type __n, const basic_string &__str) constβ Compare substring to a string. πconstexpr int compare (size_type __pos, size_type __n1, const _CharT *__s) constβ Compare substring to a C string. πconstexpr int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) constβ Compare substring against a character array. βint compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) constβ Compare substring against a character array. π₯constexpr int compare (size_type __pos1, size_type __n1, const _CharT *__s) constβ compare a chunk of urself to a C string β¨constexpr int compare (size_type __pos1, size_type __n1, const _CharT *__s, size_type __n2) constβ same but u cap the C string at__n2πconstexpr int compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) constβ Compare substring to a substring. πint compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) constβ Compare substring to a substring. πconstexpr int compare (size_type __pos, size_type __n, const basic_string &__str) constβ Compare substring to a string. πconstexpr int compare (size_type __pos, size_type __n1, const _CharT *__s) constβ Compare substring to a C string. πconstexpr int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) constβ Compare substring against a character array. π¦constexpr int compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) constβ Compare substring to a substring. π
constexpr bool contains (_CharT __x) const noexceptβ does she contain char__x? yes/no, no throw πbool contains (_CharT __x) const noexceptβ same question, other overload πconstexpr bool contains (basic_string_view< _CharT, _Traits > __x) const noexceptβ contains that string view? πΈbool contains (basic_string_view< _CharT, _Traits > __x) const noexceptβ contains that string view? (again) π¦constexpr bool contains (const _CharT *__x) const noexceptβ contains that C string? πbool contains (const _CharT *__x) const noexceptβ contains that C string? (again) β¨size_type copy (_CharT *__s, size_type __n, size_type __pos=0) constβ copies out into ur buffer, no null terminator added, careful bestie πconstexpr size_type copy (_CharT *__s, size_type __n, size_type __pos=0) constβ Copy substring into C string. πconst_reverse_iterator crbegin () const noexceptβ const reverse begin, going backwards in style πconst_reverse_iterator crend () const noexceptβ const reverse end πconst _CharT * data () const noexceptβ read-only pointer to the contents πconstexpr _CharT * data () noexceptβ Return non-const pointer to contents. π₯constexpr bool empty () const noexceptβ is she empty? πiterator end ()β iterator past the last char β¨const_iterator end () const noexceptβ const iterator past the last char πconstexpr bool ends_with (_CharT __x) const noexceptβ does she end with char__x? πbool ends_with (_CharT __x) const noexceptβ same, other overload πconstexpr bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexceptβ ends with that string view? πΈbool ends_with (basic_string_view< _CharT, _Traits > __x) const noexceptβ ends with that string view? (again) π¦constexpr bool ends_with (const _CharT *__x) const noexceptβ ends with that C string? βbool ends_with (const _CharT *__x) const noexceptβ ends with that C string? (again) π
iterator erase (__const_iterator __first, __const_iterator __last)β nukes a range βοΈiterator erase (__const_iterator __position)β nukes one char βοΈbasic_string & erase (size_type __pos=0, size_type __n=_Base::npos)β nukes__nchars starting at__pos, defaults to everything πconstexpr iterator erase (__const_iterator __first, __const_iterator __last)β Remove a range of characters. πconstexpr iterator erase (__const_iterator __position)β Remove one character. πΈiterator erase (iterator __first, iterator __last)β Remove a range of characters. π¦iterator erase (iterator __position)β Remove one character. β¨constexpr basic_string & erase (size_type __pos=0, size_type __n=npos)β Remove characters. π
constexpr size_type find (_CharT __c, size_type __pos=0) const noexceptβ Find position of a character. πsize_type find (_CharT __c, size_type __pos=0) const noexceptβ Find position of a character. πconstexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ searching a C substring, one flavor πΈconstexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a C substring. π¦size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a C substring. πconstexpr size_type find (const _CharT *__s, size_type __pos=0) const noexceptβ searching a C string, one flavor β¨constexpr size_type find (const _CharT *__s, size_type __pos=0) const noexceptβ Find position of a C string. βconstexpr size_type find (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a string. πsize_type find (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a string. πconstexpr size_type find (_CharT __c, size_type __pos=0) const noexceptβ Find position of a character. πconstexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a C substring. πconstexpr size_type find (const _CharT *__s, size_type __pos=0) const noexceptβ Find position of a C string. πconstexpr size_type find (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a string. π
constexpr size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexceptβ Find position of a different character. π΅οΈsize_type find_first_not_of (_CharT __c, size_type __pos=0) const noexceptβ Find position of a different character. πconstexpr size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ first spot that is not part of that C substring πconstexpr size_type find_first_not_of (const _CharT *__s, size_typeβ and she continues into the next part, cliffhanger bestie ππ
Okay so, bestie, buckle up, because this next batch is the find family and there are... a lot of them π but like, in a good way, I promise.
π the find_first_not_of era (yes there are twelve of these, no I'm not kidding)
size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a character not in C substring.size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a character not in C substring.constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexceptconstexpr size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexceptβ Find position of a character not in C string.constexpr size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a character not in string.size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a character not in string.constexpr size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexceptβ Find position of a different character.constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a character not in C substring.constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexceptβ Find position of a character not in C string.constexpr size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a character not in string.
Like, that's the whole vibe β first character that is not part of the set you gave it. Every overload you could ever want. iconic honestly π
β¨ and now find_first_of, the sequel nobody asked for but everybody needed
constexpr size_type find_first_of (_CharT __c, size_type __pos=0) const noexceptβ Find position of a character.size_type find_first_of (_CharT __c, size_type __pos=0) const noexceptβ Find position of a character.constexpr size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptconstexpr size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a character of C substring.size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a character of C substring.constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexceptconstexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexceptβ Find position of a character of C string.constexpr size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a character of string.size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a character of string.constexpr size_type find_first_of (_CharT __c, size_type __pos=0) const noexceptβ Find position of a character.constexpr size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find position of a character of C substring.constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexceptβ Find position of a character of C string.constexpr size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexceptβ Find position of a character of string.
She's giving "I will find the FIRST one and I will find it politely." π
π¦ find_last_not_of β same energy, but backwards
constexpr size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexceptβ Find last position of a different character.size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexceptβ Find last position of a different character.constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptconstexpr size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find last position of a character not in C substring.size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find last position of a character not in C substring.constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos=_Base::npos) const noexceptconstexpr size_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const noexceptβ Find last position of a character not in C string.constexpr size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexceptβ Find last position of a character not in string.size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexceptβ Find last position of a character not in string.constexpr size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexceptβ Find last position of a different character.constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find last position of a character not in C substring.constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const noexceptβ Find last position of a character not in C string.constexpr size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexceptβ Find last position of a character not in string.
Note bestie: the default here isnpos, not0. So if you don't hand it a__pos, it starts from the very back of the string and works its way forward. No cap. π
π find_last_of, closing out the find-iverse
constexpr size_type find_last_of (_CharT __c, size_type __pos=npos) const noexceptβ Find last position of a character.size_type find_last_of (_CharT __c, size_type __pos=npos) const noexceptβ Find last position of a character.constexpr size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptconstexpr size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find last position of a character of C substring.size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find last position of a character of C substring.constexpr size_type find_last_of (const _CharT *__s, size_type __pos=_Base::npos) const noexceptconstexpr size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexceptβ Find last position of a character of C string.constexpr size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexceptβ Find last position of a character of string.size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexceptβ Find last position of a character of string.constexpr size_type find_last_of (_CharT __c, size_type __pos=npos) const noexceptβ Find last position of a character.constexpr size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ Find last position of a character of C substring.constexpr size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexceptβ Find last position of a character of C string.constexpr size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexceptβ Find last position of a character of string.
Bestie we SURVIVED the find overloads. Drink some water. π
πΈ the little guys (access + allocator)
constexpr const_reference front () const noexceptconstexpr reference front () noexceptconstexpr allocator_type get_allocator () const noexceptβ Return copy of allocator used to construct this string.
front() gives you the very first character, and get_allocator() hands you back a copy of the allocator that built this string. β¨
π the insert family (prepare yourself, it's a big one)
iterator insert (__const_iterator __p, _CharT __c)template<typename _InputIterator> iterator insert (__const_iterator __p, _InputIterator __first, _InputIterator __last)iterator insert (const_iterator __p, size_type __n, _CharT __c)iterator insert (const_iterator __p, std::initializer_list< _CharT > __l)basic_string & insert (size_type __pos, const _CharT *__s)basic_string & insert (size_type __pos, const _CharT *__s, size_type __n)basic_string & insert (size_type __pos, size_type __n, _CharT __c)basic_string & insert (size_type __pos1, const basic_string &__str)basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n)constexpr iterator insert (__const_iterator __p, _CharT __c)β Insert one character.template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr iterator insert (const_iterator __p, _InputIterator __beg, _InputIterator __end)β Insert a range of characters.constexpr iterator insert (const_iterator __p, initializer_list< _CharT > __l)β Insert an initializer_list of characters.constexpr iterator insert (const_iterator __p, size_type __n, _CharT __c)β Insert multiple characters.iterator insert (iterator __p, _CharT __c)β Insert one character.template<class _InputIterator> void insert (iterator __p, _InputIterator __beg, _InputIterator __end)β Insert a range of characters.void insert (iterator __p, initializer_list< _CharT > __l)β Insert an initializer_list of characters.void insert (iterator __p, size_type __n, _CharT __c)β Insert multiple characters.constexpr basic_string & insert (size_type __pos, const _CharT *__s)β Insert a C string.constexpr basic_string & insert (size_type __pos, const _CharT *__s, size_type __n)β Insert a C substring.constexpr basic_string & insert (size_type __pos, size_type __n, _CharT __c)β Insert multiple characters.constexpr basic_string & insert (size_type __pos1, const basic_string &__str)β Insert value of a string.constexpr basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos)β Insert a substring.
The way that insert has TWENTY-TWO overloads and every single one of them is doing something slightly different... main character energy tbh π
π« size check + the operators
constexpr size_type length () const noexceptβ Returns the number of characters in the string, not including any null-termination.constexpr size_type max_size () const noexceptβ Returns the size() of the largest possible string.basic_string & operator+= (_CharT __c)basic_string & operator+= (const _CharT *__s)basic_string & operator+= (const basic_string &__str)basic_string & operator+= (std::initializer_list< _CharT > __l)constexpr basic_string & operator+= (const basic_string &__str)β Append a string to this string.basic_string & operator= (_CharT __c)basic_string & operator= (basic_string &&)=defaultbasic_string & operator= (const _CharT *__s)basic_string & operator= (const basic_string &)=defaultbasic_string & operator= (std::initializer_list< _CharT > __l)reference operator[] (size_type __pos)const_reference operator[] (size_type __pos) const noexceptconstexpr reference operator[] (size_type __pos)β Subscript access to the data contained in the string.constexpr const_reference operator[] (size_type __pos) const noexceptβ Subscript access to the data contained in the string.
length() counts your characters and deliberately skips the null terminator, so don't come for her when "hi" gives you 2. π«Ά
π the push/pop/reverse crew
void pop_back ()void push_back (_CharT __c)reverse_iterator rbegin ()const_reverse_iterator rbegin () const noexceptreverse_iterator rend ()const_reverse_iterator rend () const noexcept
pop_back() yeets the last character, push_back() adds one at the end, and rbegin() / rend() give you the reverse iterators so you can stroll through your string backwards like it's a catwalk. π
Obsessed.
template<typename _InputIterator> basic_string & replace (__const_iterator __i1, __const_iterator __i2, _InputIterator __j1, _InputIterator __j2)basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s)basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s, size_type __n)basic_string & replace (__const_iterator __i1, __const_iterator __i2, const basic_string &__str)basic_string & replace (__const_iterator __i1, __const_iterator __i2, size_type __n, _CharT __c)basic_string & replace (__const_iterator __i1, __const_iterator __i2, std::initializer_list< _CharT > __l)basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s)basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c)basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str)basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2)
like ok the replace family is a whole girl group with eleven members and honestly? each one ate π
constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, _CharT *__k1, _CharT *__k2)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__k1, const _CharT *__k2)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s)β swap out that[__i1, __i2)range for a whole C string πconstexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s, size_type __n)β same vibe but you're only taking a C substring, no capconstexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const basic_string &__str)β range out, string in, iconic behaviorconstexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const_iterator __k1, const_iterator __k2)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, iterator __k1, iterator __k2)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, size_type __n, _CharT __c)β replace that range with multiple copies of one character π«Άtemplate<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, _InputIterator __k1, _InputIterator __k2)β replace a range with another range, very "out with the old" energy β¨constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, initializer_list< _CharT > __l)β replace a range with aninitializer_list, so you can just vibe with braces πbasic_string & replace (iterator __i1, iterator __i2, _CharT *__k1, _CharT *__k2)template<class _InputIterator> basic_string & replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)β replace a range with another range π₯basic_string & replace (iterator __i1, iterator __i2, const _CharT *__k1, const _CharT *__k2)basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s)β replace a range with a C string, mwah πbasic_string & replace (iterator __i1, iterator __i2, const _CharT *__s, size_type __n)β replace a range with a C substringbasic_string & replace (iterator __i1, iterator __i2, const basic_string &__str)β replace a range with a string, slaybasic_string & replace (iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2)basic_string & replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l)β replace a range with aninitializer_listπ¦basic_string & replace (iterator __i1, iterator __i2, iterator __k1, iterator __k2)basic_string & replace (iterator __i1, iterator __i2, size_type __n, _CharT __c)β replace a range with multiple copies of a character πΈconstexpr basic_string & replace (size_type __pos, size_type __n, const basic_string &__str)β replace characters with the value of another string πconstexpr basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s)β replace characters with the value of a C string β¨constexpr basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)β replace characters with the value of a C substringconstexpr basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c)β replace characters with multiple copies of a characterconstexpr basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos)β replace characters with the value of another string (and yes bestie,__n2defaults tonpos)
ok breathe. that's the replace girlies. moving on π§
constexpr void reserve ()constexpr void reserve (size_type __res_arg)β tries to preallocate enough memory for the number of characters you asked forvoid reserve (size_type __res_arg)β same thing, tries to preallocate enough memory for the number of characters you asked forconstexpr void reserve (size_type __res_arg)β yeah it's here again, trying to preallocate enough memory for the number of characters πvoid resize (size_type __n)void resize (size_type __n, _CharT __c)constexpr void resize (size_type __n)β resizes the string to the number of characters you specified, periodtconstexpr void resize (size_type __n, _CharT __c)β resizes the string to the number of characters you specified β¨constexpr size_type rfind (_CharT __c, size_type __pos=npos) const noexceptβ find the last position of a character πsize_type rfind (_CharT __c, size_type __pos=npos) const noexceptβ find the last position of a character (yes, again, she's popular)constexpr size_type rfind (const _CharT *__s, size_type __pos, size_type __n) constconstexpr size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find the last position of a C substringsize_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find the last position of a C substring πconstexpr size_type rfind (const _CharT *__s, size_type __pos=_Base::npos) constconstexpr size_type rfind (const _CharT *__s, size_type __pos=npos) constβ find the last position of a C stringconstexpr size_type rfind (const basic_string &__str, size_type __pos=npos) const noexceptβ find the last position of a string πsize_type rfind (const basic_string &__str, size_type __pos=npos) const noexceptβ find the last position of a stringconstexpr size_type rfind (_CharT __c, size_type __pos=npos) const noexceptβ find the last position of a character πconstexpr size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find the last position of a C substringconstexpr size_type rfind (const _CharT *__s, size_type __pos=npos) constβ find the last position of a C stringconstexpr size_type rfind (const basic_string &__str, size_type __pos=npos) const noexceptβ find the last position of a string βvoid shrink_to_fit () noexceptconstexpr size_type size () const noexceptβ hands you the number of characters in the string, and not counting any null-termination, ok? important πconstexpr bool starts_with (_CharT __x) const noexceptbool starts_with (_CharT __x) const noexceptconstexpr bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexceptbool starts_with (basic_string_view< _CharT, _Traits > __x) const noexceptconstexpr bool starts_with (const _CharT *__x) const noexceptbool starts_with (const _CharT *__x) const noexceptbasic_string substr (size_type __pos=0, size_type __n=_Base::npos) constconstexpr basic_string substr (size_type __pos, size_type __n) &&constexpr basic_string substr (size_type __pos=0) &&constexpr basic_string substr (size_type __pos=0, size_type __n=npos) constβ get yourself a substring, little slice of the main character πconstexpr basic_string_view< _CharT, _Traits > subview (size_type __pos=0, size_type __n=npos) constβ get a subview πconstexpr basic_string_view< _CharT, _Traits > subview (size_type __pos=0, size_type __n=npos) constβ get a subviewvoid swap (basic_string &__x) noexcept(/*conditional */)constexpr void swap (basic_string &__s) noexceptβ swap contents with another string, trading cards but make it C++ π΄
π Static Public Attributes π
static const size_type nposβ the value that various member functions hand back when they fail. she's the "idk girl, not found" of the string world π
π Protected Member Functions π
constexpr void _M_swap (const _Safe_container &__x) const noexcept
π«Ά Friends π«Ά
template<typename _ItT, typename _SeqT, typename _CatT> class ::__gnu_debug::_Safe_iterator
β¨ Detailed Description β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
class __gnu_debug::basic_string< _CharT, _Traits, _Allocator >
It's literally Class std::basic_string with safety/checking/debug instrumentation. so it's the same bestie you know and love, but she went to therapy and now she checks things π
π Member Function Documentation π
template<typename _CharT, typename _Traits, typename _Alloc> template<typename _Operation> void std::basic_string< _CharT, _Traits, _Alloc >::__resize_and_overwrite (size_type __n, _Operation __op) [constexpr], [inherited]β a non-standard version ofresize_and_overwritefor C++11 and above πΈtemplate<typename _CharT, typename _Traits, typename _Alloc> template<typename _Operation> void std::basic_string< _CharT, _Traits, _Alloc >::__resize_and_overwrite (size_type __n, _Operation __op) [inherited]β same deal, a non-standard version ofresize_and_overwritefor C++11 and abovetemplate<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s, size_type __n) [inline], [constexpr], [inherited]β append a C substring β¨
Parameters
__sβ the C string you're appending__nβ how many characters you're appending
Returns
A reference to this string π«Ά
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr], [inherited]β append a string to this string π
Parameters
__strβ the string you're appending
Returns
A reference to this string
Referenced by std::basic_string< _CharT >::append(), std::basic_string< _CharT >::append(), std::basic_string< _CharT >::append(), std::basic_string< _CharT >::append(), std::__cxx11::collate< _CharT >::do_transform(), std::basic_string< _CharT >::operator+=(), std::basic_string< _CharT >::operator+=(), std::basic_string< _CharT >::operator+=(), std::operator>>(), and resize().
like ok she's referenced by ten whole functions?? main character energy fr fr π
β¨ append β Append a substring β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos,
size_type __n = npos);
[inline], [constexpr], [inherited]
okay bestie so this one is literally "glue a piece of another string onto the end of me" π
Parameters π
__strβ the string you're appending from, your source of truth fr.__posβ index of the first character of str to append. like, where do we start copy-pasting from.__nβ the number of characters to append.
Returns π
A reference to this string. (So you can chain, iykyk.)
Exceptions π¨
std::out_of_range if __pos is not a valid index. Not it throwing at you because you gave it a nonsense position π
So the tea is: this function appends __n characters from __str starting at __pos to this string. And if __n is larger than the number of available characters in __str, the remainder of __str is appended. So like, it doesn't blow up, it just gives you everything that's left. generous king behavior π
β¨ append β Append an initializer_list of characters β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::append (initializer_list< _CharT > __l);
[inline], [constexpr], [inherited]
bestie you can just yeet a whole initializer_list of characters onto the end. curly braces, go off π
Parameters πΈ
__lβ theinitializer_listof characters to append.
Returns π
A reference to this string. iconic, chaining stays winning.
β¨ append β Append multiple characters β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::append (size_type __n, _CharT __c);
[inline], [constexpr], [inherited]
the "spam the same character" button, no cap π
Parameters π
__nβ the number of characters to append.__cβ the character to use.
Returns π
A reference to this string.
Appends __n copies of __c to this string. That's it. That's the whole vibe. 'a' x 5, boom, aaaaa β¨
β¨ assign β Set value to contents of another string (move edition) β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::assign (basic_string< _CharT, _Traits, _Alloc > && __str);
[inline], [constexpr], [noexcept], [inherited]
Parameters πΈ
__strβ source string to use.
Returns π
A reference to this string.
This function sets this string to the exact contents of __str. And here's the important lil note: __str is a valid, but unspecified string. So likeβ¦ it still exists, it's not broken, but do NOT go assuming what's inside it afterward. It's giving "don't look in the box" energy π
fr fr, "valid but unspecified" means the standard won't tell you what it holds. Read it if you must, but don't count on anything.
β¨ assign β Set value to a C substring β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s, size_type __n);
[inline], [constexpr], [inherited]
Parameters π
__sβ the C string to use.__nβ number of characters to use.
Returns π
A reference to this string.
This function sets the value of this string to the first __n characters of __s. And if __n is larger than the number of available characters in __s, the remainder of __s is used. so it's not gonna yell at you for over-asking, it just gives what it's got π«Ά
β¨ assign β Set value to contents of another string β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::assign (const basic_string< _CharT, _Traits, _Alloc > & __str);
[inline], [constexpr], [inherited]
Parameters πΈ
__strβ source string to use.
Returns π
A reference to this string.
Referenced by std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::operator=(), std::basic_string< _CharT >::operator=(), std::basic_string< _CharT >::operator=(), std::basic_string< _CharT >::operator=(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_stringbuf< char >::str(), and std::basic_stringbuf< char >::str().
look at her, she's popular, everybody calls her π β¨
β¨ assign β Set value to a substring of a string β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::assign (const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos,
size_type __n = npos);
[inline], [constexpr], [inherited]
Parameters π
__strβ the string to use.__posβ index of the first character of str.__nβ number of characters to use.
Returns π
A reference to this string.
Exceptions π¨
std::out_of_range if pos is not a valid index.
This function sets this string to the substring of __str consisting of __n characters at __pos. And if __n is larger than the number of available characters in __str, the remainder of __str is used. slice-and-dice but make it safe β¨
β¨ assign β Set value to multiple characters β¨
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::assign (size_type __n, _CharT __c);
[inline], [constexpr], [inherited]
Parameters πΈ
__nβ length of the resulting string.__cβ the character to use.
Returns π
A reference to this string.
This function sets the value of this string to __n copies of character __c. filling the whole thing with one letter, main character energy π
β¨ at β Provides access to the data contained in the string β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n);
[inline], [nodiscard], [constexpr]
Parameters π
__nβ the index of the character to access.
Returns π
Read/write reference to the character.
Exceptions π¨
std::out_of_range if n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. like she does the vibe check before letting you in, and honestly? queen behavior π
β¨ at β (the unsharing one) β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n);
[inline]
Parameters πΈ
__nβ the index of the character to access.
Returns π
Read/write reference to the character.
Exceptions π¨
std::out_of_range if n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. Success results in unsharing the string. π
β¨ at β (const flavored, with the tags) β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
const_reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n) const;
[inline], [nodiscard], [constexpr]
Parameters π
__nβ the index of the character to access.
Returns π
Read-only (const) reference to the character.
Exceptions π¨
std::out_of_range if n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. look but don't touch bestie π
β¨ at β (const flavored, no tags) β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
const_reference
std::basic_string< _CharT, _Traits, _Allocator >::at (size_type __n) const;
[inline]
Parameters πΈ
__nβ the index of the character to access.
Returns π
Read-only (const) reference to the character.
Exceptions π¨
std::out_of_range if n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails.
β¨ at β (inherited, read/write) β¨
template<typename _CharT, typename _Traits, typename _Alloc>
reference
std::basic_string< _CharT, _Traits, _Alloc >::at (size_type __n);
[inline], [nodiscard], [constexpr], [inherited]
Parameters π
__nβ the index of the character to access.
Returns π
Read/write reference to the character.
Exceptions π¨
std::out_of_range if n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails.
β¨ at β (inherited, const) β¨
template<typename _CharT, typename _Traits, typename _Alloc>
const_reference
std::basic_string< _CharT, _Traits, _Alloc >::at (size_type __n) const;
[inline], [nodiscard], [constexpr], [inherited]
Parameters πΈ
__nβ the index of the character to access.
Returns π
Read-only (const) reference to the character.
Exceptions π¨
std::out_of_range if n is an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails.
β¨ back β (const) β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
const_reference
std::basic_string< _CharT, _Traits, _Allocator >::back () const;
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reference to the data at the last element of the string. just the last character, pls don't poke it π
β¨ back β (read/write) β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
reference
std::basic_string< _CharT, _Traits, _Allocator >::back ();
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read/write reference to the data at the last element of the string. last character, but you can edit her now π
β¨ capacity β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type
std::basic_string< _CharT, _Traits, _Allocator >::capacity () const;
[inline], [nodiscard], [constexpr], [noexcept]
Returns the total number of characters that the string can hold before needing to allocate more memory. like, how many more besties can she fit before she has to go shopping for a bigger place ποΈβ¨
β¨ compare β Compare to a string β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
int
std::basic_string< _CharT, _Traits, _Allocator >::compare (const basic_string< _CharT, _Traits, _Allocator > & __str) const;
[inline], [nodiscard], [constexpr]
Parameters πΈ
__strβ string to compare against.
Returns π
Integer < 0, 0, or > 0.
Returns an integer < 0 if this string is ordered before __str, 0 if their values are equivalent, or > 0 if this string is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of size() and str.size(). The function then compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.
so basically: negative = she comes first, zero = twins, positive = she comes after. and if they're equal all the way through, the shorter one wins the "ordered first" spot π
β¨ compare β Compare substring to a string β¨
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
int
std::basic_string< _CharT, _Traits, _Allocator >::compare (size_type __pos,
size_type __n,
const basic_string< _CharT, _Traits, _Allocator > & __str) const;
[inline], [nodiscard], [constexpr]
Compare substring to a string.
__posβ index of the first character of the substring π―__nβ how many characters are in that substring__strβ the string you're comparing against
Returns β an integer that's < 0, 0, or > 0.
So here's the tea, bestie: you form the substring of this string out of the __n characters starting at __pos. Then: integer < 0 if that substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. It figures out the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). Then it compares the two by calling traits::compare(substring.data(),str.data(),rlen). If that comparison comes back nonzero it just returns it β otherwise the shorter one is ordered first. Periodt. π
π Compare substring to a string (yes, again, but a different overload)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> int std::basic_string<
_CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n,
const basic_string< _CharT, _Traits, _Allocator > & __str) const
[inline]
Okay so this one is literally the compare-substring-to-a-string, the standard-issue one, marked [inline]. πΈ
Parameters
__posβ index of first character of substring.__nβ number of characters in substring.__strβ string to compare against.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n characters starting at __pos. Returns an integer < 0 if the substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). The function then compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π¦
β¨ Compare substring to a C string
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> int std::basic_string<
_CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n1,
const _CharT * __s) const [inline], [nodiscard], [constexpr]
Look at those attributes bestie β [inline], [nodiscard], and [constexpr]. It's giving overachiever. π
Parameters
__posβ index of first character of substring.__n1β number of characters in substring.__sβ C string to compare against.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at pos. Returns an integer < 0 if the substring is ordered before __s, 0 if their values are equivalent, or > 0 if the substring is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and the length of a string constructed from __s. The function then compares the two string by calling traits::compare(substring.data(),__s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π
π Compare substring against a character array
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> int std::basic_string<
_CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n1,
const _CharT * __s, size_type __n2) const [inline], [nodiscard],
[constexpr]
Parameters
__posβ index of first character of substring.__n1β number of characters in substring.__sβ character array to compare against.__n2β number of characters ofs.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at __pos. Form a string from the first __n2 characters of __s. Returns an integer < 0 if this substring is ordered before the string from __s, 0 if their values are equivalent, or > 0 if this substring is ordered after the string from __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __n2. The function then compares the two strings by calling traits::compare(substring.data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π
NB:smust have at leastn2characters,'\0'has no special meaning. Not me warning you twice β it really does not care about your null terminator, bestie. π
π Compare substring against a character array (the [inline]-only twin)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> int std::basic_string<
_CharT, _Traits, _Allocator >::compare (size_type __pos, size_type __n1,
const _CharT * __s, size_type __n2) const [inline]
Same energy, just [inline] with no extra flair. Lowkey iconic. β
Parameters
__posβ index of first character of substring.__n1β number of characters in substring.__sβ character array to compare against.__n2β number of characters ofs.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at __pos. Form a string from the first __n2 characters of __s. Returns an integer < 0 if this substring is ordered before the string from __s, 0 if their values are equivalent, or > 0 if this substring is ordered after the string from __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __n2. The function then compares the two strings by calling traits::compare(substring.data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. πΈ
NB:smust have at leastn2characters,'\0'has no special meaning. π«Ά
π Compare substring to a substring (a.k.a. the double-substring situation)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> int std::basic_string<
_CharT, _Traits, _Allocator >::compare (size_type __pos1, size_type
__n1, const basic_string< _CharT, _Traits, _Allocator > & __str,
size_type __pos2, size_type __n2 = npos) const [inline], [nodiscard],
[constexpr]
Two positions, two lengths, one vibe check. Note the __n2 = npos default β it'll just run to the end of __str unless you say otherwise. π¦
Parameters
__pos1β index of first character of substring.__n1β number of characters in substring.__strβ string to compare against.__pos2β index of first character of substring ofstr.__n2β number of characters in substring ofstr.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at __pos1. Form the substring of __str from the __n2 characters starting at __pos2. Returns an integer < 0 if this substring is ordered before the substring of __str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of __str. Determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. The function then compares the two strings by calling traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π§
π Compare substring to a substring, again
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> int std::basic_string<
_CharT, _Traits, _Allocator >::compare (size_type __pos1, size_type
__n1, const basic_string< _CharT, _Traits, _Allocator > & __str,
size_type __pos2, size_type __n2 = npos) const [inline]
Yeah bestie, it's the same overload again, just the [inline]-without-[nodiscard]/[constexpr] version. The header really said "here's both, choose your fighter." π
Parameters
__pos1β index of first character of substring.__n1β number of characters in substring.__strβ string to compare against.__pos2β index of first character of substring ofstr.__n2β number of characters in substring ofstr.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at __pos1. Form the substring of __str from the __n2 characters starting at __pos2. Returns an integer < 0 if this substring is ordered before the substring of __str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of __str. Determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. The function then compares the two strings by calling traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π
π Compare substring to a string β the inherited one
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
const [inline], [nodiscard], [constexpr], [inherited]
Notice the template params dropped their defaults here, and it picked up [inherited] β it's getting passed down the family line. Main character energy, fr fr. π₯
Parameters
__posβ index of first character of substring.__nβ number of characters in substring.__strβ string to compare against.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n characters starting at __pos. Returns an integer < 0 if the substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). The function then compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. β¨
π Compare substring to a C string β inherited edition
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s) const [inline], [nodiscard],
[constexpr], [inherited]
Parameters
__posβ index of first character of substring.__n1β number of characters in substring.__sβ C string to compare against.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at pos. Returns an integer < 0 if the substring is ordered before __s, 0 if their values are equivalent, or > 0 if the substring is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and the length of a string constructed from __s. The function then compares the two string by calling traits::compare(substring.data(),__s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π
π¦ Compare substring against a character array β inherited edition
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s, size_type __n2) const [inline],
[nodiscard], [constexpr], [inherited]
Parameters
__posβ index of first character of substring.__n1β number of characters in substring.__sβ character array to compare against.__n2β number of characters ofs.
Returns β Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at __pos. Then form a string from the first __n2 characters of __s. It hands back an integer that's < 0 if this substring sorts before the string made from __s, 0 if their values are equivalent, or > 0 if this substring sorts after it. π
It figures out the effective length rlen of the strings to compare as the smallest of the length of the substring and __n2. Then it compares the two strings by calling traits::compare(substring.data(),s,rlen). If the result of that comparison is nonzero it just returns it, otherwise the shorter one is ordered first. β¨
NB:smust have at leastn2characters, and'\0'has no special meaning here. no cap.
compare β substring vs. substring π
template<typename _CharT, typename _Traits, typename _Alloc>
int std::basic_string<_CharT, _Traits, _Alloc>::compare(size_type __pos1,
size_type __n1, const basic_string<_CharT, _Traits, _Alloc>& __str,
size_type __pos2, size_type __n2 = npos) const;
[inline], [nodiscard], [constexpr], [inherited]
Ok so this one is compare substring to a substring. π¦
Parameters
__pos1β Index of first character of substring.__n1β Number of characters in substring.__strβ String to compare against.__pos2β Index of first character of substring of str.__n2β Number of characters in substring of str.
Returns
Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at __pos1. Form the substring of __str from the __n2 characters starting at __pos2. It returns an integer that's < 0 if this substring is ordered before the substring of __str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of __str. It determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. Then it compares the two strings by calling
traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen)
If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first. π«Ά
copy β copy a substring into a C string π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type
std::basic_string<_CharT, _Traits, _Alloc>::copy(_CharT* __s, size_type __n,
size_type __pos = 0) const;
[constexpr], [inherited]
Copy substring into C string. π§
Parameters
__sβ C string to copy value into.__nβ Number of characters to copy.__posβ Index of first character to copy.
Returns
Number of characters actually copied.
Exceptions
std::out_of_rangeβ If__pos > size().
It copies up to __n characters starting at __pos into the C string __s. If __pos is greater than size(), out_of_range gets thrown. π
data β non-const pointer to the contents β¨
template<typename _CharT, typename _Traits, typename _Alloc>
_CharT* std::basic_string<_CharT, _Traits, _Alloc>::data();
[inline], [nodiscard], [constexpr], [noexcept], [inherited]
Return non-const pointer to contents. This is a pointer to the character sequence held by the string. Modifying the characters in the sequence is allowed. π
empty β is it giving nothing? π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
bool std::basic_string<_CharT, _Traits, _Allocator>::empty() const;
[inline], [nodiscard], [constexpr], [noexcept]
Returns true if the string is empty. Equivalent to *this == "". πΈ
erase β removing characters, five whole ways π
erase β remove a range (const_iterator version)
template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(
__const_iterator __first, __const_iterator __last);
[inline], [constexpr], [inherited]
Remove a range of characters.
Parameters
__firstβ Iterator referencing the first character to remove.__lastβ Iterator referencing the end of the range.
Returns
Iterator referencing location of first after removal.
It removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. π«Ά
erase β remove one character (const_iterator version)
template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(
__const_iterator __position);
[inline], [constexpr], [inherited]
Remove one character.
Parameters
__positionβ Iterator referencing the character to remove.
Returns
iterator referencing same location after removal.
It removes the character at __position from this string. The value of the string doesn't change if an error is thrown. π
erase β remove a range (iterator version)
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::iterator
std::basic_string<_CharT, _Traits, _Alloc>::erase(iterator __first,
iterator __last);
[inherited]
Remove a range of characters.
Parameters
__firstβ Iterator referencing the first character to remove.__lastβ Iterator referencing the end of the range.
Returns
Iterator referencing location of first after removal.
It removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. β¨
erase β remove one character (iterator version)
template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::erase(
iterator __position);
[inline], [inherited]
Remove one character.
Parameters
__positionβ Iterator referencing the character to remove.
Returns
iterator referencing same location after removal.
It removes the character at __position from this string. The value of the string doesn't change if an error is thrown. π
erase β remove characters by index + count
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string& std::basic_string<_CharT, _Traits, _Alloc>::erase(
size_type __pos = 0, size_type __n = npos);
[inline], [constexpr], [inherited]
Remove characters.
Parameters
__posβ Index of first character to remove (default0).__nβ Number of characters to remove (default remainder).
Returns
Reference to this string.
Exceptions
std::out_of_rangeβ Ifposis beyond the end of this string.
It removes __n characters from this string starting at __pos. The length of the string is reduced by __n. If there are < __n characters to remove, the remainder of the string gets truncated. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown. π
Referenced by std::getline(), std::operator>>(), std::basic_string<_CharT>::pop_back(), and resize().
find β the search era π
find β position of a character
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(_CharT __c,
size_type __pos = 0) const;
[nodiscard], [constexpr], [noexcept]
Find position of a character.
Parameters
__cβ Character to locate.__posβ Index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, it searches forward for __c within this string. If found, it returns the index where it was found. If not found, it returns npos. π
find β position of a character (second overload)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(_CharT __c,
size_type __pos = 0) const;
[noexcept]
Find position of a character.
Parameters
__cβ Character to locate.__posβ Index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, it searches forward for __c within this string. If found, it returns the index where it was found. If not found, it returns npos. β¨
find β position of a C substring
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(const _CharT* __s,
size_type __pos, size_type __n) const;
[nodiscard], [constexpr], [noexcept]
Find position of a C substring.
Parameters
__sβ C string to locate.__posβ Index of character to search from.__nβ Number of characters fromsto search for.
Returns
Index of start of first occurrence.
Starting from __pos, it searches forward for the first __n characters in __s within this string. If found, it returns the index where it begins. If not found, it returns npos. π¦
find β position of a C substring (second overload)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(const _CharT* __s,
size_type __pos, size_type __n) const;
[noexcept]
Find position of a C substring.
Parameters
__sβ C string to locate.__posβ Index of character to search from.__nβ Number of characters fromsto search for.
Returns
Index of start of first occurrence.
Starting from __pos, it searches forward for the first __n characters in __s within this string. If found, it returns the index where it begins. If not found, it returns npos. πΈ
find β position of a C string
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(const _CharT* __s,
size_type __pos = 0) const;
[inline], [nodiscard], [constexpr], [noexcept]
Find position of a C string.
Parameters
__sβ C string to locate.__posβ Index of character to search from (default0).
Returns
Index of start of first occurrence.
Starting from __pos, it searches forward for the value of __s within this string. If found, it returns the index where it begins. If not found, it returns npos. π«Ά
find β position of a string
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(
const basic_string<_CharT, _Traits, _Allocator>& __str,
size_type __pos = 0) const;
[inline], [nodiscard], [constexpr], [noexcept]
Find position of a string.
Parameters
__strβ String to locate.__posβ Index of character to search from (default0).
Returns
Index of start of first occurrence.
Starting from __pos, it searches forward for value of __str within this string. If found, it returns the index where it begins. If not found, it returns npos. π
find β position of a string (second overload)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string<_CharT, _Traits, _Allocator>::find(
const basic_string<_CharT, _Traits, _Allocator>& __str,
size_type __pos = 0) const;
[inline], [noexcept]
Find position of a string.
Parameters
__strβ String to locate.__posβ Index of character to search from (default0).
Returns
Index of start of first occurrence.
Starting from __pos, it searches forward for value of __str within this string. If found, it returns the index where it begins. If not found, it returns npos. π
find π
find β _CharT __c π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
_Alloc >::find (_CharT __c, size_type __pos = 0) const [nodiscard],
[constexpr], [noexcept], [inherited]
Okay bestie, this one is literally "find position of a character". π No cap.
Parameters
__cβ the character to locate.__posβ index of character to search from (default0).
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.
Referencesnpos, andstd::size().
find β const _CharT * __s, size_type __pos, size_type __n π¦
template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
_Alloc >::find (const _CharT * __s, size_type __pos, size_type __n)
const [nodiscard], [constexpr], [noexcept], [inherited]
Find position of a C substring. It's giving "substring hunt". β¨
Parameters
__sβ C string to locate.__posβ index of character to search from.__nβ number of characters fromsto 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.
Referencesstd::data(),npos, andstd::size().
Referenced bystd::basic_string< _CharT >::find(),std::basic_string< _CharT >::find(),std::basic_string< _CharT >::find(), andstd::basic_string< _CharT >::find_first_of().
find β const _CharT * __s, size_type __pos = 0 π
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::find (const _CharT * __s,
size_type __pos = 0) const [inline], [nodiscard], [constexpr],
[noexcept], [inherited]
Find position of a C string. It's like, the C-string vibe check. π¦
Parameters
__sβ C string to locate.__posβ index of character to search from (default0).
Returns
Index of start of first occurrence.
Starting from __pos, searches forward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos.
find β const basic_string<...>& __str, size_type __pos = 0 π
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::find (const basic_string<
_CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const [inline],
[nodiscard], [constexpr], [noexcept], [inherited]
Find position of a string. Bestie string searching realness. π
Parameters
__strβ string to locate.__posβ index of character to search from (default0).
Returns
Index of start of first occurrence.
Starting from __pos, searches forward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos.
find_first_not_of π
find_first_not_of β _CharT __c (default template args) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
(_CharT __c, size_type __pos = 0) const [nodiscard], [constexpr],
[noexcept]
Find position of a different character. It's giving "not this one". π
Parameters
__cβ character to avoid.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β _CharT __c (default template args, [noexcept] only) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
(_CharT __c, size_type __pos = 0) const [noexcept]
Find position of a different character. Same vibe, just [noexcept] and no [nodiscard]/[constexpr]. π«Ά
Parameters
__cβ character to avoid.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β const _CharT * __s, size_type __pos, size_type __n (default template args) π¦
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard],
[constexpr], [noexcept]
Find position of a character not in C substring. Avoiding characters like a pro. β¨
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search from.__nβ number of characters from__sto consider.
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β const _CharT * __s, size_type __pos, size_type __n (default template args, [noexcept] only) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
(const _CharT * __s, size_type __pos, size_type __n) const [noexcept]
Find position of a character not in C substring. Same as above but lowkey only [noexcept]. π
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search from.__nβ number of characters from__sto consider.
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β const _CharT * __s, size_type __pos = 0 (default template args) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
(const _CharT * __s, size_type __pos = 0) const [inline], [nodiscard],
[constexpr], [noexcept]
Find position of a character not in C string. C-string avoidance, slay. π
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character not contained in __s within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β const basic_string<...>& __str, size_type __pos = 0 (default template args) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
(const basic_string< _CharT, _Traits, _Allocator > & __str, size_type
__pos = 0) const [inline], [nodiscard], [constexpr], [noexcept]
Find position of a character not in string. String bestie avoidance. π
Parameters
__strβ string containing characters to avoid.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β const basic_string<...>& __str, size_type __pos = 0 (default template args, [noexcept] only) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::find_first_not_of
(const basic_string< _CharT, _Traits, _Allocator > & __str, size_type
__pos = 0) const [inline], [noexcept]
Find position of a character not in string. Just [noexcept], no frills. π«Ά
Parameters
__strβ string containing characters to avoid.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β _CharT __c (inherited) π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
_Alloc >::find_first_not_of (_CharT __c, size_type __pos = 0) const
[nodiscard], [constexpr], [noexcept], [inherited]
Find position of a different character. This one is [inherited], periodt. π
Parameters
__cβ character to avoid.__posβ index of character to search from (default0).
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.
Referencesnpos, andstd::size().
find_first_not_of β const _CharT * __s, size_type __pos, size_type __n (inherited) π¦
template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
_Alloc >::find_first_not_of (const _CharT * __s, size_type __pos,
size_type __n) const [nodiscard], [constexpr], [noexcept],
[inherited]
Find position of a character not in C substring. Inherited energy. β¨
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search from.__nβ number of characters from__sto 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.
Referencesnpos, andstd::size().
find_first_not_of β const _CharT * __s, size_type __pos = 0 (inherited) π
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of (const
_CharT * __s, size_type __pos = 0) const [inline], [nodiscard],
[constexpr], [noexcept], [inherited]
Find position of a character not in C string. Inherited C-string avoidance. π
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character not contained in __s within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_not_of β const basic_string<...>& __str, size_type __pos = 0 (inherited) π
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of (const
basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = 0)
const [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find position of a character not in string. Inherited string avoidance, final boss. π
Parameters
__strβ string containing characters to avoid.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos.
Referenced bystd::basic_string< _CharT >::find_first_not_of(),std::basic_string< _CharT >::find_first_not_of(), andstd::basic_string< _CharT >::find_first_not_of().
heads up bestie, this stretch is pure overload energy β same function name, a whole fleet of flavors, and every single one is getting its moment. no skipping, no merging, we're doing all of them. π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (_CharT __c,
size_type __pos = 0) const
specifiers: [inline], [nodiscard], [constexpr], [noexcept]
Find position of a character. π
__cβ Character to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for the character __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to find(__c, __pos).
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (_CharT __c,
size_type __pos = 0) const
specifiers: [inline], [noexcept]
Find position of a character. π¦ (yes, same vibe, slightly different specifier list β the way that they're separate entries and we're keeping both. periodt.)
__cβ Character to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for the character __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to find(__c, __pos).
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (const
_CharT * __s, size_type __pos, size_type __n) const
specifiers: [nodiscard], [constexpr], [noexcept]
Find position of a character of C substring. πΈ
__sβ String containing characters to locate.__posβ Index of character to search from.__nβ Number of characters from s to search for.
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (const
_CharT * __s, size_type __pos, size_type __n) const
specifiers: [noexcept]
Find position of a character of C substring. π
__sβ String containing characters to locate.__posβ Index of character to search from.__nβ Number of characters from s to search for.
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (const
_CharT * __s, size_type __pos = 0) const
specifiers: [inline], [nodiscard], [constexpr], [noexcept]
Find position of a character of C string. β¨
__sβ String containing characters to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (const
basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = 0) const
specifiers: [inline], [nodiscard], [constexpr], [noexcept]
Find position of a character of string. π«Ά
__strβ String containing characters to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_first_of (const
basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = 0) const
specifiers: [inline], [noexcept]
Find position of a character of string. π
__strβ String containing characters to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::find_first_of (_CharT __c,
size_type __pos = 0) const
specifiers: [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find position of a character. π (inherited flavor, iconic behavior)
__cβ Character to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for the character __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to find(__c, __pos).
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
_Alloc >::find_first_of (const _CharT * __s, size_type __pos, size_type __n) const
specifiers: [nodiscard], [constexpr], [noexcept], [inherited]
Find position of a character of C substring. π«
__sβ String containing characters to locate.__posβ Index of character to search from.__nβ Number of characters from s to search for.
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
References npos, and std::size().
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::find_first_of (const
_CharT * __s, size_type __pos = 0) const
specifiers: [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find position of a character of C string. π
__sβ String containing characters to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::find_first_of (const
basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const
specifiers: [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find position of a character of string. π§
__strβ String containing characters to locate.__posβ Index of character to search from (default 0).
Returns: Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.
Referenced by std::basic_string< _CharT >::find_first_of(), and std::basic_string< _CharT >::find_first_of().
π and now the backwards girlies: find_last_not_of π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of
(_CharT __c, size_type __pos = npos) const
specifiers: [nodiscard], [constexpr], [noexcept]
Find last position of a different character. π
__cβ Character to avoid.__posβ Index of character to search back from (default end).
Returns: Index of last occurrence.
Starting from __pos, searches backward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of
(_CharT __c, size_type __pos = npos) const
specifiers: [noexcept]
Find last position of a different character. π
__cβ Character to avoid.__posβ Index of character to search back from (default end).
Returns: Index of last occurrence.
Starting from __pos, searches backward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of
(const _CharT * __s, size_type __pos, size_type __n) const
specifiers: [nodiscard], [constexpr], [noexcept]
Find last position of a character not in C substring. πΈ
__sβ C string containing characters to avoid.__posβ Index of character to search back from.__nβ Number of characters from s to consider.
Returns: Index of last occurrence.
Starting from __pos, searches backward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of
(const _CharT * __s, size_type __pos, size_type __n) const
specifiers: [noexcept]
Find last position of a character not in C substring. π
__sβ C string containing characters to avoid.__posβ Index of character to search back from.__nβ Number of characters from s to consider.
Returns: Index of last occurrence.
Starting from __pos, searches backward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of
(const _CharT * __s, size_type __pos = npos) const
specifiers: [inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character not in C string. β
okay so that last find_last_not_of overload was mid-explanation β here's the rest of its tea, bestie:
Parameters
__sβ C string containing characters to avoid. π«__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character not contained in __s within this string. If found, returns the index where it was found. If not found, returns npos. π
πΈ find_last_not_of β the basic_string bestie (with _Allocator)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character not in string. π
Parameters
__strβ String containing characters to avoid.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos. periodt β¨
π same energy, less constexpr
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_not_of (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [noexcept]
Find last position of a character not in string.
Parameters
__strβ String containing characters to avoid.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos. no notes π
π¦ find_last_not_of β the single-char version (inherited)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of (_CharT __c, size_type __pos = npos) const [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a different character. it's giving "not this one, literally anything but this one" π
Parameters
__cβ Character to avoid.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.
References npos, and std::size().
π find_last_not_of β C substring edition (inherited)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of (const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character not in C substring. π
Parameters
__sβ C string containing characters to avoid.__posβ Index of character to search back from.__nβ Number of characters fromsto consider.
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character not contained in the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
References npos, and std::size().
β find_last_not_of β plain C string edition (inherited)
template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of (const _CharT * __s, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character not in C string.
Parameters
__sβ C string containing characters to avoid.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character not contained in __s within this string. If found, returns the index where it was found. If not found, returns npos. iconic π
π find_last_not_of β basic_string edition (inherited)
template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character not in string.
Parameters
__strβ String containing characters to avoid.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos.
Referenced by std::basic_string< _CharT >::find_last_not_of(), std::basic_string< _CharT >::find_last_not_of(), and std::basic_string< _CharT, std::char_traits< _CharT >, std::allocator< _CharT > >::swap(). look at her being popular π
π₯ find_last_of β single char, the constexpr one
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (_CharT __c, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character.
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to rfind(__c, __pos).
β¨ find_last_of β same but no constexpr
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (_CharT __c, size_type __pos = npos) const [inline], [noexcept]
Find last position of a character.
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to rfind(__c, __pos).
πΈ find_last_of β C substring, constexpr era
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]
Find last position of a character of C substring. π
Parameters
__sβ C string containing characters to locate.__posβ Index of character to search back from.__nβ Number of characters fromsto search for.
Returns
Index of last occurrence.
Starting from __pos, searches backward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
π find_last_of β C substring, no constexpr
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (const _CharT * __s, size_type __pos, size_type __n) const [noexcept]
Find last position of a character of C substring.
Parameters
__sβ C string containing characters to locate.__posβ Index of character to search back from.__nβ Number of characters fromsto search for.
Returns
Index of last occurrence.
Starting from __pos, searches backward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
π find_last_of β whole C string
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (const _CharT * __s, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character of C string.
Parameters
__sβ C string containing characters to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos. slay π
π find_last_of β basic_string, constexpr edition
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character of string.
Parameters
__strβ String containing characters to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.
β find_last_of β basic_string, no constexpr
template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Allocator = std::allocator<_CharT>> size_type std::basic_string< _CharT, _Traits, _Allocator >::find_last_of (const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [noexcept]
Find last position of a character of string.
Parameters
__strβ String containing characters to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos. π
π find_last_of β single char (inherited)
template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string< _CharT, _Traits, _Alloc >::find_last_of (_CharT __c, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character.
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to rfind(__c, __pos).
π§ find_last_of β C substring (inherited)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits, _Alloc >::find_last_of (const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character of C substring.
Parameters
__sβ C string containing characters to locate.__posβ Index of character to search back from.__nβ Number of characters fromsto search for.
Returns
Index of last occurrence.
Starting from __pos, it searches backward for one of the first __n characters of __s inside this string. Found it? You get the index where it was. Not found? You get npos. That's it, that's the whole story. π
References npos, and std::size().
find_last_of β the C-string glow-up β¨
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::find_last_of (const _CharT * __s, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character of C string.
Parameters
__sβ C string containing characters to locate.__posβ Index of character to search back from (default end).
Returns Index of last occurrence.
Starting from __pos, it searches backward for one of the characters of __s inside this string. If it finds one, it returns the index where it was found. If not found, it returns npos. bestie it really said "no character, no answer". π«Ά
find_last_of β the string-object remix πΈ
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::find_last_of (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character of string.
Parameters
__strβ String containing characters to locate.__posβ Index of character to search back from (default end).
Returns Index of last occurrence.
Starting from __pos, it searches backward for one of the characters of __str inside this string. If found, it returns the index where it was found. If not found, it returns npos.
Referenced by std::basic_string< _CharT >::find_last_of(), and std::basic_string< _CharT >::find_last_of().
front β meet the first character π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> const_reference
std::basic_string< _CharT, _Traits, _Allocator >::front () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reference to the data at the first element of the string. Peek, don't touch. π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> reference
std::basic_string< _CharT, _Traits, _Allocator >::front ()
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read/write reference to the data at the first element of the string. Now you can touch. main character energy fr. π
get_allocator β receipts on the allocator π§Ύ
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> allocator_type
std::basic_string< _CharT, _Traits, _Allocator >::get_allocator () const
[inline], [nodiscard], [constexpr], [noexcept]
Return copy of allocator used to construct this string. Like, who's been managing this memory the whole time? Here's their @. π
insert β one character, const_iterator edition π
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (__const_iterator __p, _CharT __c)
[inline], [constexpr], [inherited]
Insert one character.
Parameters
__pβ Iterator referencing position in string to insert at.__cβ The character to insert.
Returns Iterator referencing newly inserted char.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts character __c at the position referenced by __p. If adding the character causes the length to exceed max_size(), length_error is thrown. If __p is beyond end of string, out_of_range is thrown. And the good news: the value of the string doesn't change if an error is thrown. no half-finished slay. β¨
insert β a whole range, const_iterator edition π
template<typename _CharT, typename _Traits, typename _Alloc> template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
iterator std::basic_string< _CharT, _Traits, _Alloc >::insert (const_iterator __p, _InputIterator __beg, _InputIterator __end)
[inline], [constexpr], [inherited]
Insert a range of characters.
Parameters
__pβ Const_iterator referencing location in string to insert at.__begβ Start of range.__endβ End of range.
Returns Iterator referencing the first inserted char.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts characters in range [beg,end). If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
insert β the initializer_list, const_iterator edition π¦
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (const_iterator __p, initializer_list< _CharT > __l)
[inline], [constexpr], [inherited]
Insert an initializer_list of characters.
Parameters
__pβ Iterator referencing location in string to insert at.__lβ The initializer_list of characters to insert.
Exceptions
std::length_errorβ If new length exceedsmax_size().
insert β multiple copies, const_iterator edition π
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (const_iterator __p, size_type __n, _CharT __c)
[inline], [constexpr], [inherited]
Insert multiple characters.
Parameters
__pβ Const_iterator referencing location in string to insert at.__nβ Number of characters to insert__cβ The character to insert.
Returns Iterator referencing the first inserted char.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts __n copies of character __c starting at the position referenced by iterator __p. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
Referenced by std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), and std::basic_string< _CharT >::insert().
insert β one character, plain iterator edition π
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, _CharT __c)
[inline], [inherited]
Insert one character.
Parameters
__pβ Iterator referencing position in string to insert at.__cβ The character to insert.
Returns Iterator referencing newly inserted char.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts character __c at the position referenced by __p. If adding the character causes the length to exceed max_size(), length_error is thrown. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown.
insert β a range, plain iterator edition πΊ
template<typename _CharT, typename _Traits, typename _Alloc> template<class _InputIterator>
void std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, _InputIterator __beg, _InputIterator __end)
[inline], [inherited]
Insert a range of characters.
Parameters
__pβ Iterator referencing location in string to insert at.__begβ Start of range.__endβ End of range.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts characters in range [__beg,__end). If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
insert β initializer_list, plain iterator edition π
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, initializer_list< _CharT > __l)
[inline], [inherited]
Insert an initializer_list of characters.
Parameters
__pβ Iterator referencing location in string to insert at.__lβ The initializer_list of characters to insert.
Exceptions
std::length_errorβ If new length exceedsmax_size().
insert β multiple copies, plain iterator edition π«
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, size_type __n, _CharT __c)
[inline], [inherited]
Insert multiple characters.
Parameters
__pβ Iterator referencing location in string to insert at.__nβ Number of characters to insert__cβ The character to insert.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts __n copies of character __c starting at the position referenced by iterator __p. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
insert β the C string drop-in π₯
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s)
[inline], [constexpr], [inherited]
Insert a C string.
Parameters
__posβ Position in string to insert at.__sβ The C string to insert.
Returns Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().std::out_of_rangeβ If pos is beyond the end of this string.
Inserts the first n characters of __s starting at __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.
insert β the C substring glow π§
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s, size_type __n)
[inline], [constexpr], [inherited]
Insert a C substring.
Parameters
__posβ Position in string to insert at.__sβ The C string to insert.__nβ The number of characters to insert.
Returns Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().std::out_of_rangeβ If__posis beyond the end of this string.
Inserts the first __n characters of __s starting at __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.
insert β the repeat-button edition, by index π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, size_type __n, _CharT __c)
[inline], [constexpr], [inherited]
Insert multiple characters.
Parameters
__posβ Index in string to insert at.__nβ Number of characters to insert__cβ The character to insert.
Returns Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().std::out_of_rangeβ If__posis beyond the end of this string.
Inserts __n copies of character __c starting at index __pos. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos > length(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.
π«Ά insert β slide a whole string in
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1,
const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline], [constexpr], [inherited]
Insert value of a string. bestie it does exactly what it says on the tin β¨
Parameters
__pos1β Position in string to insert at.__strβ The string to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().
So the vibe is: it inserts the value of __str starting at __pos1. If adding characters causes the length to exceed max_size(), length_error is thrown. And the glow-up rule: the value of the string doesn't change if an error is thrown. no cap π§
π insert β but make it a substring
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1,
const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos2,
size_type __n = npos)
[inline], [constexpr], [inherited]
Insert a substring. yes queen, selective insertion π
Parameters
__pos1β Position in string to insert at.__strβ The string to insert.__pos2β Start of characters in str to insert.__nβ Number of characters to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().std::out_of_rangeβ If pos1 > size() or__pos2> str.size().
Starting at pos1, insert __n character of __str beginning with __pos2. If adding characters causes the length to exceed max_size(), length_error is thrown. If __pos1 is beyond the end of this string or __pos2 is beyond the end of __str, out_of_range is thrown. The value of the string doesn't change if an error is thrown. π she's dramatic but she's honest
π¦ length β how many characters we got
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::length () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns the number of characters in the string, not including any null-termination. periodt. she's not counting that sneaky null terminator, she's better than that π
πΈ max_size β the ceiling, the limit, the vibe check
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> size_type
std::basic_string< _CharT, _Traits, _Allocator >::max_size () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns the size() of the largest possible string. the absolute biggest she can be, iconic π
β operator+= β append era
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::operator+= (const
basic_string< _CharT, _Traits, _Alloc > & __str)
[inline], [constexpr], [inherited]
Append a string to this string. just tacking it right on the end, lowkey the most used thing ever π
Parameters
__strβ The string to append.
Returns
Reference to this string. π«Ά
π
operator[] β the non-const one, she's editable
template<typename _CharT, typename _Traits, typename _Alloc> reference
std::basic_string< _CharT, _Traits, _Alloc >::operator[] (size_type
__pos)
[inline], [nodiscard], [constexpr], [inherited]
Subscript access to the data contained in the string.
Parameters
__posβ The index of the character to access.
Returns
Read/write reference to the character. β¨
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().)
fr fr bestie, this one does NOT check your bounds. she will simply let you walk off the edge. if you want a seatbelt, go see at(). π¨
π operator[] β the const one, she's read-only and that's her whole thing
template<typename _CharT, typename _Traits, typename _Alloc> const_reference
std::basic_string< _CharT, _Traits, _Alloc >::operator[] (size_type
__pos) const
[inline], [nodiscard], [constexpr], [noexcept], [inherited]
Subscript access to the data contained in the string.
Parameters
__posβ The index of the character to access.
Returns
Read-only (constant) reference to the character. π
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().)
Referenced by std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::front(), std::basic_string< _CharT >::front(), and std::basic_string< _CharT >::front(). π (yes she's listed six whole times, the algorithm said so, we don't question the algorithm)
π replace β range of characters gets swapped for a C string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, const _CharT * __s)
[inline], [constexpr], [inherited]
Replace range of characters with C string.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, the characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. π§
π replace β range gets swapped for a C *sub*string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, const _CharT * __s, size_type __n)
[inline], [constexpr], [inherited]
Replace range of characters with C substring.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.__nβ Number of characters from s to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, the first __n characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. β
π replace β range gets swapped for a whole string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, const basic_string< _CharT, _Traits, _Alloc
> & __str)
[inline], [constexpr], [inherited]
Replace range of characters with string.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__strβ String value to insert.
Returns
Reference to this string. π«Ά
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, the value of __str is inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. π
β¨ replace β range gets swapped for a bunch of copies of one char
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, size_type __n, _CharT __c)
[inline], [constexpr], [inherited]
Replace range of characters with multiple characters.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__nβ Number of characters to insert.__cβ Character to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, __n copies of __c are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. π
πΈ replace β range gets swapped for another range (const_iterator edition)
template<typename _CharT, typename _Traits, typename _Alloc> template<class
_InputIterator, typename = std::_RequireInputIter<_InputIterator>>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace
(const_iterator __i1, const_iterator __i2, _InputIterator __k1,
_InputIterator __k2)
[inline], [constexpr], [inherited]
Replace range of characters with range.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__k1β Iterator referencing start of range to insert.__k2β Iterator referencing end of range to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. π¦
π§ replace β range gets swapped for an initializer_list
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (const_iterator
__i1, const_iterator __i2, initializer_list< _CharT > __l)
[inline], [constexpr], [inherited]
Replace range of characters with initializer_list.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__lβ The initializer_list of characters to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. π (yes, the text really says [__k1,__k2) here even though the parameter is named __l β that's literally what the page says, so we're saying it too, no edits, no cap)
π replace β range gets swapped for another range (iterator edition)
template<typename _CharT, typename _Traits, typename _Alloc> template<class
_InputIterator> basic_string & std::basic_string< _CharT, _Traits,
_Alloc >::replace (iterator __i1, iterator __i2, _InputIterator __k1,
_InputIterator __k2)
[inline], [inherited]
Replace range of characters with range.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__k1β Iterator referencing start of range to insert.__k2β Iterator referencing end of range to insert.
Returns
Reference to this string. π
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. β
π replace β range gets swapped for a C string (iterator edition)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const _CharT * __s)
[inline], [inherited]
Replace range of characters with C string.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.
Returns
Reference to this string. π«Ά
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, the characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. π
πΈ replace β swap a whole range for a chunk of a C string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const _CharT * __s, size_type __n) [inline], [inherited]
okay so this is the "Replace range of characters with C substring" girly π
you hand her two iterators and she just deletes the whole vibe between them, then drops in the first __n characters of __s like it's nothing.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.__nβ Number of characters from s to insert.
Returns
Reference to this string. (she gives herself back, main character energy π)
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, the first __n characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
πΈ replace β swap a whole range for a whole other string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline], [inherited]
Replace range of characters with string. literally the same as above but your source is a basic_string instead of a C string, so no __n required, she takes the whole thing π«Ά
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__strβ String value to insert.
Returns
Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, the value of __str is inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
πΈ replace β swap a whole range for an initializer_list
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, initializer_list< _CharT > __l) [inline], [inherited]
Replace range of characters with initializer_list. curly-brace girlies rise up π
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__lβ Theinitializer_listof characters to insert.
Returns
Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
πΈ replace β swap a whole range for a bunch of copies of one char
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, size_type __n, _CharT __c) [inline], [inherited]
Replace range of characters with multiple characters. yes bestie, she will absolutely print the same character __n times for you, no judgement π
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__nβ Number of characters to insert.__cβ Character to insert.
Returns
Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__i1,__i2). In place, __n copies of __c are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
πΈ replace β index-based, whole other string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline], [constexpr], [inherited]
Replace characters with value from another string. notice we've switched from iterators to indexes here β she contains multitudes β¨
Parameters
__posβ Index of first character to replace.__nβ Number of characters to be replaced.__strβ String to insert.
Returns
Reference to this string.
Exceptions
std::out_of_rangeβ If pos is beyond the end of this string.std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__pos,__pos+__n) from this string. In place, the value of __str is inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
Referenced by β okay so this one is iconic and everyone wants a piece of her π here is the full guest list, and no I did not make any of these up:
std::basic_string< _CharT >::append()std::basic_string< _CharT >::assign()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::insert()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()std::basic_string< _CharT >::replace()
(that's nine insert()s and eleven replace()s, fr fr β they're all the same name because they're different overloads, the page just lists them like this π)
πΈ replace β index-based, plain C string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, const _CharT * __s) [inline], [constexpr], [inherited]
Replace characters with value of a C string. she takes all of __s, zero counting, we love a low-effort queen π
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__sβ C string to insert.
Returns
Reference to this string.
Exceptions
std::out_of_rangeβ If pos > size().std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the characters of __s are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
πΈ replace β index-based, C *sub*string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc
>::replace (size_type __pos, size_type __n1, const _CharT * __s,
size_type __n2) [inline], [constexpr], [inherited]
Replace characters with value of a C substring. now you do get to say how much of __s you want, and she'll be chill about it π¦
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__sβ C string to insert.__n2β Number of characters from s to use.
Returns
Reference to this string.
Exceptions
std::out_of_rangeβ If pos1 > size().std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the first __n2 characters of __s are inserted, or all of __s if __n2 is too large. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
πΈ replace β index-based, __n2 copies of one char
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, size_type __n2, _CharT __c) [inline], [constexpr],
[inherited]
Replace characters with multiple characters. four arguments, one job: out with __n1, in with __n2 copies of __c π
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__n2β Number of characters to insert.__cβ Character to insert.
Returns
Reference to this string.
Exceptions
std::out_of_rangeβ If__pos>size().std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [pos,pos + n1) from this string. In place, __n2 copies of __c are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
πΈ replace β index-based, slice of another string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos1,
size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos2, size_type __n2 = npos) [inline], [constexpr],
[inherited]
Replace characters with value from another string. this is the deluxe version bestie β you get to pick where in __str to start (__pos2) and how much of it to take (__n2), and __n2 even defaults to npos so she'll just grab the rest if you don't say π
Parameters
__pos1β Index of first character to replace.__n1β Number of characters to be replaced.__strβ String to insert.__pos2β Index of first character of str to use.__n2β Number of characters from str to use.
Returns
Reference to this string.
Exceptions
std::out_of_rangeβ If__pos1>size()or__pos2>__str.size().std::length_errorβ If new length exceedsmax_size().
Removes the characters in the range [__pos1,__pos1 + n) from this string. In place, the value of __str is inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
π§ reserve β the no-argument one (plot twist: it shrinks)
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> void std::basic_string<
_CharT, _Traits, _Allocator >::reserve () [constexpr]
Equivalent to shrink_to_fit().
not me expecting "reserve" to reserve something π with zero arguments she does the literal opposite, she lets go. it's giving "decluttering era". π
π§ reserve(size_type __res_arg) β preallocate like a girlboss
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> void std::basic_string<
_CharT, _Traits, _Allocator >::reserve (size_type __res_arg) [constexpr]
Attempt to preallocate enough memory for specified number of characters.
Parameters
__res_argβ Number of characters required.
Exceptions
std::length_errorβ If__res_argexceedsmax_size().
This function attempts to reserve enough memory for the string to hold the specified number of characters. If the number requested is more than max_size(), length_error is thrown.
The advantage of this function is that if optimal code is a necessity and the user can determine the string length that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of string data.
π§ reserve(size_type __res_arg) β same energy, different declaration
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> void std::basic_string<
_CharT, _Traits, _Allocator >::reserve (size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
Parameters
__res_argβ Number of characters required.
Exceptions
std::length_errorβ If__res_argexceedsmax_size().
okay so real talk, this function is literally trying to reserve enough memory for the string to hold the number of characters you asked for. If what you asked for is more than max_size(), then length_error gets thrown, no cap. π
The whole glow-up here is: if you need optimal code and you actually know how long your string is gonna be, you can reserve that memory up front and prevent a possible reallocation of memory and copying of string data. Pre-planning? iconic. π
β¨ reserve (the constexpr one) β¨
template<typename _CharT, typename _Traits, typename _Alloc>
void std::basic_string< _CharT, _Traits, _Alloc >::reserve(size_type __res_arg) [constexpr], [inherited]
Attempt to preallocate enough memory for specified number of characters. π
Parameters
__res_argβ Number of characters required.
Exceptions
std::length_errorβ If__res_argexceedsmax_size().
This function attempts to reserve enough memory for the string to hold the specified number of characters. If the number requested is more than max_size(), length_error is thrown.
The advantage of this function is that if optimal code is a necessity and the user can determine the string length that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of string data. so smart, bestie.
References capacity(), get_allocator(), and std::size().
Referenced by std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::tr2::operator>>(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow().
πΈ resize (one arg) πΈ
template<typename _CharT, typename _Traits, typename _Alloc>
void std::basic_string< _CharT, _Traits, _Alloc >::resize(size_type __n) [inline], [constexpr], [inherited]
Resizes the string to the specified number of characters. π
Parameters
__nβ Number of characters the string should contain.
This function will resize the string to the specified length. If the new size is smaller than the string's current size the string is truncated, otherwise the string is extended and new characters are default-constructed. For basic types such as char, this means setting them to 0. so like, they get the ol' zero treatment.
π¦ resize (two args) π¦
template<typename _CharT, typename _Traits, typename _Alloc>
void std::basic_string< _CharT, _Traits, _Alloc >::resize(size_type __n, _CharT __c) [constexpr], [inherited]
Resizes the string to the specified number of characters. π
Parameters
__nβ Number of characters the string should contain.__cβ Character to fill any new elements.
This function will resize the string to the specified number of characters. If the number is smaller than the string's current size the string is truncated, otherwise the string is extended and new elements are set to __c.
References append(), erase(), and size().
Referenced by std::basic_string< _CharT >::resize().
π rfind (template, _CharT overload, constexpr version) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(_CharT __c, size_type __pos = npos) const [nodiscard], [constexpr], [noexcept]
Find last position of a character. π
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
- Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
π rfind (template, _CharT overload, non-constexpr version) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(_CharT __c, size_type __pos = npos) const [noexcept]
Find last position of a character. π
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
- Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
π rfind (template, C substring, constexpr version) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]
Find last position of a C substring. π«Ά
Parameters
__sβ C string to locate.__posβ Index of character to search back from.__nβ Number of characters from s to search for.
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos.
π rfind (template, C substring, non-constexpr version) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const _CharT * __s, size_type __pos, size_type __n) const [noexcept]
Find last position of a C substring. π«Ά
Parameters
__sβ C string to locate.__posβ Index of character to search back from.__nβ Number of characters from s to search for.
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos.
β rfind (template, C string) β
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const _CharT * __s, size_type __pos = npos) const [inline], [nodiscard], [constexpr]
Find last position of a C string. π
Parameters
__sβ C string to locate.__posβ Index of character to start search at (default end).
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos.
π rfind (template, basic_string, constexpr + noexcept version) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept]
Find last position of a string. π¦
Parameters
__strβ String to locate.__posβ Index of character to search back from (default end).
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos.
π rfind (template, basic_string, noexcept-only version) π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::rfind(const basic_string< _CharT, _Traits, _Allocator > & __str, size_type __pos = npos) const [inline], [noexcept]
Find last position of a string. π¦
Parameters
__strβ String to locate.__posβ Index of character to search back from (default end).
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos.
π rfind (inherited, _CharT overload) π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits, _Alloc >::rfind(_CharT __c, size_type __pos = npos) const [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a character. π
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
- Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
References npos, and std::size().
π rfind (inherited, C substring) π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits, _Alloc >::rfind(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a C substring. π«Ά
Parameters
__sβ C string to locate.__posβ Index of character to search back from.__nβ Number of characters from s to search for.
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos.
References std::min(), npos, and std::size().
π rfind (inherited, C string) π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::rfind(const _CharT * __s, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [inherited]
Find last position of a C string. π
Parameters
__sβ C string to locate.__posβ Index of character to start search at (default end).
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos.
π rfind (inherited, basic_string) π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::rfind(const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const [inline], [nodiscard], [constexpr], [noexcept], [inherited]
Find last position of a string. π¦
Parameters
__strβ String to locate.__posβ Index of character to search back from (default end).
Returns
- Index of start of last occurrence.
Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos.
Referenced by std::basic_string< _CharT >::find_last_of(), std::basic_string< _CharT >::rfind(), std::basic_string< _CharT >::rfind(), std::basic_string< _CharT >::rfind(), and std::basic_string< _CharT >::rfind().
π size π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>>
size_type std::basic_string< _CharT, _Traits, _Allocator >::size() const [inline], [nodiscard], [constexpr], [noexcept]
Returns the number of characters in the string, not including any null-termination. so like, the actual vibes count, not the sneaky hidden \0 at the end, iykyk.
π§ substr π§
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string std::basic_string< _CharT, _Traits, _Alloc >::substr(size_type __pos = 0, size_type __n = npos) const [inline], [nodiscard], [constexpr], [inherited]
Get a substring. βοΈ
okay bestie we're in the home stretch of the member function tour and honestly this part ate π
__posβ Index of first character (default 0).__nβ Number of characters in substring (default remainder).
Returns: The new string. β¨
Exceptions: std::out_of_range if __pos > size().
So the vibe here is: it constructs and returns a brand new string, built from the __n characters that start at __pos. If your string is too short? No stress, it just uses the remainder of the characters. But if __pos is past the end of the string, out_of_range gets yeeted at you. π«Ά
the subview one, take one π¦
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string_view< _CharT, _Traits > std::basic_string< _CharT, _Traits,
_Alloc >::subview (size_type __pos = 0, size_type __n = npos) const
[inline], [nodiscard], [constexpr], [inherited]
Get a subview.
Parameters
__posβ Index of first character (default 0).__nβ Number of characters in subview (default remainder).
Returns: The subview. π
Exceptions: std::out_of_range if __pos > size().
It constructs and returns a subview using the __n characters starting at __pos. If the string is too short, it uses the remainder of the characters. And if __pos is beyond the end of the string, out_of_range is thrown. periodt.
the subview one, take two π (yes, the page really does list it twice β icon behaviour, we don't question it)
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string_view< _CharT, _Traits > std::basic_string< _CharT, _Traits,
_Alloc >::subview (size_type __pos = 0, size_type __n = npos) const
[inline], [nodiscard], [constexpr], [inherited]
Get a subview.
Parameters
__posβ Index of first character (default 0).__nβ Number of characters in subview (default remainder).
Returns: The subview. πΈ
Exceptions: std::out_of_range if __pos > size().
Constructs and returns a subview using the __n characters starting at __pos. Too short a string? It uses the remainder of the characters. __pos past the end of the string? out_of_range is thrown. same energy, same facts, no notes π
swap β the trade π€
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::swap (basic_string<
_CharT, _Traits, _Alloc > & __s) [constexpr], [noexcept], [inherited]
Swap contents with another string.
Parameters
__sβ String to swap with.
It exchanges the contents of this string with that of __s in constant time. literally the fastest glow-up in the whole file, no cap. β¨
References basic_string(), and get_allocator().
Referenced by std::basic_string< _CharT >::assign(), and std::basic_string< _CharT >::operator=().
π Member Data Documentation π
npos β the fail state, but make it static π
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
typename _Allocator = std::allocator<_CharT>> const size_type
std::basic_string< _CharT, _Traits, _Allocator >::npos [static]
Value returned by various member functions when they fail. yes bestie, npos is the group chat's "something went wrong" text. π
β¨ Author β¨
Generated automatically by Doxygen for libstdc++ from the source code.
and that's a wrap on the whole page, bestie!! π you read all 15 parts, which is genuinely main character energy. go hydrate, go compile something, go be iconic. π¦π
this was sourced from libstdc++, page __gnu_debu...llocator >(3), straight outta the libstdc++ manual pages β mwah, no cap, slay π
π
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms