STD::WSTRING(3)
π NAME π
okay so first things first, bestie: this page is std::basic_string< _CharT, _Traits, _Alloc >(3), and it lives in the Library Functions Manual. yes the title line up top is all cryptic and truncated like std::basic..., _Alloc >(3) β that's just the header being dramatic, we know who she is π
What does she do? Managing sequences of characters and character-like objects. That's it. That's the whole job. And she does it iconically.
π«Ά heads up: this manual is LONG, like 19 parts long, and you're reading part 1 right now. Don't panic. We're gonna get through it together.
β¨ SYNOPSIS β¨
First, the summoning ritual:
#include <string>
That's the include. That's the whole spell. Say it with me: #include <string> πΈ
π Inherited by
She's not alone in this world, and these little ones carry her DNA:
__gnu_debug::basic_string< char >__gnu_debug::basic_string< wchar_t >__gnu_debug::basic_string< char16_t >__gnu_debug::basic_string< char32_t >__gnu_debug::basic_string< _CharT, _Traits, _Allocator >
no cap, that last one is literally her but with a different allocator name spelled out. the family resemblance is real π
π Public Types π
okay so this is the part where the page just dumps the whole type zoo on you, and ngl a bunch of these show up twice β same name, two different underlying recipes. That's not a typo, that's just how the page lists them, so I'm giving you every single one, in order, no skips, no shortcuts. periodt π
typedef _Char_alloc_type allocator_typeβ the allocator type, first version, handed to you under the nameallocator_type.typedef _Alloc allocator_typeβ and here'sallocator_typeagain, defined off_Allocthis time. yes, same name. she contains multitudes.typedef __gnu_cxx::__normal_iterator< const_pointer, basic_string > const_iteratorβ aconst_iteratorbuilt from__gnu_cxx::__normal_iterator< const_pointer, basic_string >. read-only energy, we love her π¦typedef __gnu_cxx::__normal_iterator< const_pointer, basic_string > const_iteratorβ same thing, listed again. the page said it twice and I respect the commitment.typedef _Alloc_traits::const_pointer const_pointerβconst_pointer, defined off_Alloc_traits::const_pointer.typedef _CharT_alloc_traits::const_pointer const_pointerβ andconst_pointeragain, this time off_CharT_alloc_traits::const_pointer.typedef _Alloc_traits::const_reference const_referenceβconst_reference, from_Alloc_traits::const_reference.typedef const value_type & const_referenceβconst_referenceagain, and this one is literallyconst value_type &. very demure, very direct.typedef std::reverse_iterator< const_iterator > const_reverse_iteratorβconst_reverse_iterator, aka aconst_iteratorthat walks backwards. main character walking into the room backwards just to be extra β¨typedef std::reverse_iterator< const_iterator > const_reverse_iteratorβ same one, second appearance. she said it twice because it slaps.typedef _Alloc_traits::difference_type difference_typeβdifference_type, from_Alloc_traits::difference_type.typedef _CharT_alloc_traits::difference_type difference_typeβdifference_typeagain, from_CharT_alloc_traits::difference_type.typedef __gnu_cxx::__normal_iterator< pointer, basic_string > iteratorβiterator, built from__gnu_cxx::__normal_iterator< pointer, basic_string >. now you can actually change stuff πtypedef __gnu_cxx::__normal_iterator< pointer, basic_string > iteratorβ listed again, same definition. consistency queen.typedef _Alloc_traits::pointer pointerβpointer, from_Alloc_traits::pointer.typedef _CharT_alloc_traits::pointer pointerβpointeragain, from_CharT_alloc_traits::pointer.typedef _Alloc_traits::reference referenceβreference, from_Alloc_traits::reference.typedef value_type & referenceβreferenceagain, and it's justvalue_type &. short, sweet, gets the job done πtypedef std::reverse_iterator< iterator > reverse_iteratorβreverse_iterator, areverse_iteratorwrapped arounditerator. backwards but make it editable.typedef std::reverse_iterator< iterator > reverse_iteratorβ yep, the same one again. two for two πtypedef _Alloc_traits::size_type size_typeβsize_type, from_Alloc_traits::size_type. sizes! lengths! the math of it all!typedef _CharT_alloc_traits::size_type size_typeβsize_typeagain, from_CharT_alloc_traits::size_type.typedef _Traits traits_typeβtraits_type, which is_Traits. she's literally the traits template param, wearing a lil name tag π·οΈtypedef _Traits traits_typeβ same, second time. the page really said "and you're gonna hear it again."typedef _Traits::char_type value_typeβvalue_type, from_Traits::char_type. this is the thing all the strings are made of πtypedef _Traits::char_type value_typeβ andvalue_typeonce more, identical. okay we get it, she's important π
and that's the type list, every last one, nothing skipped, nothing merged, no invented lore. there's a LOT more of this page coming, bestie β 18 more parts β so keep your #include <string> warm π«Ά
π Public Member Functions π
okay bestie, this is the member function roster and it's giving main character energy. every single signature is copied exactly β constexpr twins, allocator overloads, deleted stuff, all of it. no skipping, no summarising, periodt.
basic_string () noexceptβ default constructor creates an empty string. iconic.constexpr basic_string () noexcept(/*conditional */)β default constructor creates an empty string. the constexpr version said "let me glow too."template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc())β construct string as copy of a range. range vibes.template<class _InputIterator> basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc())β construct string as copy of a range. the non-constexpr one is here too.constexpr basic_string (basic_string &&__str) noexceptβ move construct string. move it, move it.basic_string (basic_string &&__str) noexceptβ move construct string. yes, the non-constexpr twin.basic_string (basic_string &&__str, const _Alloc &__a)β no description in the original, bestie. we're not inventing lore.constexpr basic_string (basic_string &&__str, const _Alloc &__a) noexcept(_Alloc_traits::_S_always_equal())β no description in the original. just the signature, slaying.constexpr basic_string (basic_string &&__str, size_type __pos, const _Alloc &__a=_Alloc())β no description in the original. mysterious.constexpr basic_string (basic_string &&__str, size_type __pos, size_type __n, const _Alloc &__a=_Alloc())β no description in the original. still iconic.basic_string (const _Alloc &__a)β construct an empty string using allocator a. allocator core.constexpr basic_string (const _Alloc &__a) noexceptβ construct an empty string using allocator a. constexpr edition.template<typename = _RequireAllocator<_Alloc>> constexpr basic_string (const _CharT *__s, const _Alloc &__a=_Alloc())β construct string as copy of a C string. C string copy.template<typename = _RequireAllocator<_Alloc>> basic_string (const _CharT *__s, const _Alloc &__a=_Alloc())β construct string as copy of a C string. non-constexpr twin.constexpr basic_string (const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())β construct string initialized by a character array. character array tea.basic_string (const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())β construct string initialized by a character array. same but non-constexpr.constexpr basic_string (const basic_string &__str)β construct string with copy of value of__str. copy that.basic_string (const basic_string &__str)β construct string with copy of value ofstr. note the description saysstr, bestie, we keep it exact.constexpr basic_string (const basic_string &__str, const _Alloc &__a)β no description in the original. just vibes.basic_string (const basic_string &__str, const _Alloc &__a)β no description in the original. twin energy.constexpr basic_string (const basic_string &__str, size_type __pos, const _Alloc &__a=_Alloc())β construct string as copy of a substring. substring moment.basic_string (const basic_string &__str, size_type __pos, const _Alloc &__a=_Alloc())β construct string as copy of a substring. non-constexpr.constexpr basic_string (const basic_string &__str, size_type __pos, size_type __n)β construct string as copy of a substring. more substring.basic_string (const basic_string &__str, size_type __pos, size_type __n)β construct string as copy of a substring. yes.constexpr basic_string (const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a)β construct string as copy of a substring. with allocator.basic_string (const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a)β construct string as copy of a substring. non-constexpr with allocator.constexpr basic_string (initializer_list< _CharT > __l, const _Alloc &__a=_Alloc())β construct string from an initializer list. initializer list slay.basic_string (initializer_list< _CharT > __l, const _Alloc &__a=_Alloc())β construct string from an initializer list. non-constexpr twin.basic_string (nullptr_t)=deleteβ no description in the original. it's deleted, so don't try it.basic_string (nullptr_t)=deleteβ no description in the original. yes, it's listed twice, we keep both.template<typename = _RequireAllocator<_Alloc>> constexpr basic_string (size_type __n, _CharT __c, const _Alloc &__a=_Alloc())β construct string as multiple characters. multiple characters.basic_string (size_type __n, _CharT __c, const _Alloc &__a=_Alloc())β construct string as multiple characters. non-constexpr.constexpr ~basic_string ()β destroy the string instance. destruction, but make it couture.~basic_string () noexceptβ destroy the string instance. noexcept edition.template<typename _Operation> constexpr void __resize_and_overwrite (size_type __n, _Operation __op)β non-standard version ofresize_and_overwritefor C++11 and above. non-standard but useful.template<typename _Operation> void __resize_and_overwrite (size_type __n, _Operation __op)β non-standard version ofresize_and_overwritefor C++11 and above. non-constexpr twin.template<typename _InputIterator> basic_string< _CharT, _Traits, _Alloc > & _M_replace_dispatch (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2, __false_type)β no description in the original. internal dispatch tea.template<typename _InIterator> _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, forward_iterator_tag)β no description in the original. internal construct tea.template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & append (_InputIterator __first, _InputIterator __last)β append a range of characters. append szn.template<class _InputIterator> basic_string & append (_InputIterator __first, _InputIterator __last)β append a range of characters. non-constexpr twin.constexpr basic_string & append (const _CharT *__s)β append a C string. C string append.basic_string & append (const _CharT *__s)β append a C string. non-constexpr.constexpr basic_string & append (const _CharT *__s, size_type __n)β append a C substring. substring append.basic_string & append (const _CharT *__s, size_type __n)β append a C substring. non-constexpr.constexpr basic_string & append (const basic_string &__str)β append a string to this string. string to string.basic_string & append (const basic_string &__str)β append a string to this string. non-constexpr.constexpr basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos)β append a substring. substring append again.basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos)β append a substring. non-constexpr.constexpr basic_string & append (initializer_list< _CharT > __l)β append aninitializer_listof characters. list append.basic_string & append (initializer_list< _CharT > __l)β append aninitializer_listof characters. non-constexpr.constexpr basic_string & append (size_type __n, _CharT __c)β append multiple characters. multiple chars.basic_string & append (size_type __n, _CharT __c)β append multiple characters. non-constexpr.template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & assign (_InputIterator __first, _InputIterator __last)β set value to a range of characters. assign range.template<class _InputIterator> basic_string & assign (_InputIterator __first, _InputIterator __last)β set value to a range of characters. non-constexpr.constexpr basic_string & assign (basic_string &&__str) noexcept(_Alloc_traits::_S_nothrow_move())β set value to contents of another string. move assign.basic_string & assign (basic_string &&__str) noexcept(allocator_traits< _Alloc >::is_always_equal::value)β set value to contents of another string. non-constexpr move assign.constexpr basic_string & assign (const _CharT *__s)β set value to contents of a C string. C string assign.basic_string & assign (const _CharT *__s)β set value to contents of a C string. non-constexpr.constexpr basic_string & assign (const _CharT *__s, size_type __n)β set value to a C substring. C substring assign.basic_string & assign (const _CharT *__s, size_type __n)β set value to a C substring. non-constexpr.constexpr basic_string & assign (const basic_string &__str)β set value to contents of another string. string assign.basic_string & assign (const basic_string &__str)β set value to contents of another string. non-constexpr.constexpr basic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos)β set value to a substring of a string. substring assign.basic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos)β set value to a substring of a string. non-constexpr.constexpr basic_string & assign (initializer_list< _CharT > __l)β set value to aninitializer_listof characters. list assign.basic_string & assign (initializer_list< _CharT > __l)β set value to aninitializer_listof characters. non-constexpr.constexpr basic_string & assign (size_type __n, _CharT __c)β set value to multiple characters. multiple chars assign.basic_string & assign (size_type __n, _CharT __c)β set value to multiple characters. non-constexpr.constexpr reference at (size_type __n)β provides access to the data contained in the string. access, bestie.reference at (size_type __n)β provides access to the data contained in the string. non-constexpr.constexpr const_reference at (size_type __n) constβ provides access to the data contained in the string. const edition.const_reference at (size_type __n) constβ provides access to the data contained in the string. non-constexpr const edition.reference back ()β no description in the original. back access tea.constexpr const_reference back () const noexceptβ no description in the original. constexpr const back.const_reference back () const noexceptβ no description in the original. non-constexpr const back.constexpr reference back () noexceptβ no description in the original. constexpr back.iterator begin ()β no description in the original. begin iterator.constexpr const_iterator begin () const noexceptβ no description in the original. constexpr const begin.const_iterator begin () const noexceptβ no description in the original. non-constexpr const begin.constexpr iterator begin () noexceptβ no description in the original. constexpr begin.constexpr const _CharT * c_str () const noexceptβ return const pointer to null-terminated contents. c_str core.const _CharT * c_str () const noexceptβ return const pointer to null-terminated contents. non-constexpr.constexpr size_type capacity () const noexceptβ no description in the original. capacity tea.size_type capacity () const noexceptβ no description in the original. non-constexpr capacity.constexpr const_iterator cbegin () const noexceptβ no description in the original. cbegin.const_iterator cbegin () const noexceptβ no description in the original. non-constexpr cbegin.constexpr const_iterator cend () const noexceptβ no description in the original. cend.const_iterator cend () const noexceptβ no description in the original. non-constexpr cend.constexpr void clear () noexceptβ no description in the original. clear it.void clear () noexceptβ no description in the original. non-constexpr clear.constexpr int compare (const _CharT *__s) const noexceptβ compare to a C string. compare szn.int compare (const _CharT *__s) const noexceptβ compare to a C string. non-constexpr.constexpr int compare (const basic_string &__str) constβ compare to a string. string compare.int compare (const basic_string &__str) constβ compare to a string. non-constexpr.constexpr int compare (size_type __pos, size_type __n, const basic_string &__str) constβ compare substring to a string. substring compare.int compare (size_type __pos, size_type __n, const basic_string &__str) constβ compare substring to a string. non-constexpr.constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s) constβ compare substring to a C string. substring vs C string.int compare (size_type __pos, size_type __n1, const _CharT *__s) constβ compare substring to a C string. non-constexpr.constexpr int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) constβ compare substring against a character array. substring vs char array.int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) constβ compare substring against a character array. non-constexpr.constexpr int compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) constβ compare substring to a substring. substring vs substring, the finale.int compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) constβ compare substring to a substring. non-constexpr twin.
okay bestie we're STILL in the SYNOPSIS and she is long β grab a snack π this is the part where the overloads start showing up in pairs like twins who refuse to be separated π
constexpr bool contains (_CharT __x) const noexceptβ does she contain this one lil character?constexprera, so she can answer at compile time β¨bool contains (_CharT __x) const noexceptβ same question, non-constexprtwin πΈconstexpr bool contains (basic_string_view< _CharT, _Traits > __x) const noexceptβ does she contain this wholebasic_string_view?constexprone π«bool contains (basic_string_view< _CharT, _Traits > __x) const noexceptβ the other twin, noconstexprπconstexpr bool contains (const _CharT *__x) const noexceptβ does she contain this C-string?constexprflavor π₯bool contains (const _CharT *__x) const noexceptβ the plain twin, same question π¦constexpr size_type copy (_CharT *__s, size_type __n, size_type __pos=0) constβ copy substring into C string π«Ά she takes__ncharacters starting from__pos=0and drops them into your C stringsize_type copy (_CharT *__s, size_type __n, size_type __pos=0) constβ same mission, non-constexpredition πconstexpr const_reverse_iterator crbegin () const noexceptβ the reverse-beginning,constflavor,constexprflavor, she's giving everything πconst_reverse_iterator crbegin () const noexceptβ her non-constexprtwin πconstexpr const_reverse_iterator crend () const noexceptβ reverse-end,const+constexprβconst_reverse_iterator crend () const noexceptβ the non-constexprtwin, no blurb needed, she's self-explanatory πconstexpr const _CharT * data () const noexceptβ return const pointer to contents β peek, don't touch πconst _CharT * data () const noexceptβ same const-pointer energy, non-constexprπΈconstexpr _CharT * data () noexceptβ return non-const pointer to contents β okay now you CAN touch, behave yourself π_CharT * data () noexcept(false)β non-const pointer to contents, and yes bestie thatnoexcept(false)is right there in the source, do not come for me πconstexpr bool empty () const noexceptβ is she empty?constexprsaid it first β¨bool empty () const noexceptβ is she empty? other twin πiterator end ()β end iterator, plain and unbothered π¦constexpr const_iterator end () const noexceptβconstend iterator,constexpredition π«const_iterator end () const noexceptβconstend iterator, noconstexprπconstexpr iterator end () noexceptβ non-constend iterator that ISconstexprπ₯constexpr bool ends_with (_CharT __x) const noexceptβ does she end with this character?constexprπbool ends_with (_CharT __x) const noexceptβ same Q, non-constexprtwin πΈconstexpr bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexceptβ does she end with thisbasic_string_view?constexprβ¨bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexceptβ her twin πconstexpr bool ends_with (const _CharT *__x) const noexceptβ does she end with this C-string?constexprπ₯bool ends_with (const _CharT *__x) const noexceptβ her twin, noconstexprπ¦constexpr iterator erase (__const_iterator __first, __const_iterator __last)β remove a range of characters β full yeet,__firstto__lastπconstexpr iterator erase (__const_iterator __position)β remove one character β surgical yeet, one single victim πiterator erase (iterator __first, iterator __last)β remove a range of characters, non-constexprtwin, and note she takesiteratorhere not__const_iteratorπiterator erase (iterator __position)β remove one character, twin energy πconstexpr basic_string & erase (size_type __pos=0, size_type __n=npos)β remove characters β defaults are__pos=0and__n=npos, so she'll clear the whole thing if you don't say otherwise πbasic_string & erase (size_type __pos=0, size_type __n=npos)β same defaults, non-constexprtwin πΈconstexpr size_type find (_CharT __c, size_type __pos=0) const noexceptβ find position of a character β where is__chiding, starting at__pos=0πsize_type find (_CharT __c, size_type __pos=0) const noexceptβ her twin πconstexpr size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find position of a C substring, you supply both__posand__nβ¨size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ twin π¦constexpr size_type find (const _CharT *__s, size_type __pos=0) const noexceptβ find position of a C string,__pos=0default π«size_type find (const _CharT *__s, size_type __pos=0) const noexceptβ twin πconstexpr size_type find (const basic_string &__str, size_type __pos=0) const noexceptβ find position of a string πΈsize_type find (const basic_string &__str, size_type __pos=0) const noexceptβ twin πconstexpr size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexceptβ find position of a different character β the first one that is NOT__cπsize_type find_first_not_of (_CharT __c, size_type __pos=0) const noexceptβ twin πconstexpr size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find position of a character not in C substring β¨size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ twin π¦constexpr size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexceptβ find position of a character not in C string,__pos=0default πsize_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexceptβ twin πconstexpr size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexceptβ find position of a character not in string πΈsize_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexceptβ twin βconstexpr size_type find_first_of (_CharT __c, size_type __pos=0) const noexceptβ find position of a character πsize_type find_first_of (_CharT __c, size_type __pos=0) const noexceptβ twin πconstexpr size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find position of a character of C substring β¨size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ twin π¦constexpr size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexceptβ find position of a character of C string π«size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexceptβ twin πconstexpr size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexceptβ find position of a character of string πΈsize_type find_first_of (const basic_string &__str, size_type __pos=0) const noexceptβ twin πconstexpr size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexceptβ find last position of a different character β and heads up, the default here is__pos=npos, not 0 πsize_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexceptβ twin πconstexpr size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find last position of a character not in C substring β¨size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ twin π¦constexpr size_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const noexceptβ find last position of a character not in C string,__pos=nposdefault πsize_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const noexceptβ twin πconstexpr size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexceptβ find last position of a character not in string πΈsize_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexceptβ twin βconstexpr size_type find_last_of (_CharT __c, size_type __pos=npos) const noexceptβ find last position of a character, default__pos=nposπsize_type find_last_of (_CharT __c, size_type __pos=npos) const noexceptβ twin πconstexpr size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find last position of a character of C substring β¨size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ twin π¦constexpr size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexceptβ find last position of a character of C string π«size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexceptβ twin πconstexpr size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexceptβ find last position of a character of string πΈsize_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexceptβ twin πreference front ()β the front, plain edition, no blurb in the source, she just is πconstexpr const_reference front () const noexceptβconstfront,constexprβ¨const_reference front () const noexceptβconstfront, noconstexprπΈconstexpr reference front () noexceptβ non-constfront that'sconstexprπ₯constexpr allocator_type get_allocator () const noexceptβ return copy of allocator used to construct this string β she hands you a copy, not the real one π«Άallocator_type get_allocator () const noexceptβ same copy-of-the-allocator deal, non-constexprtwin πconstexpr iterator insert (__const_iterator __p, _CharT __c)β insert one character β one single character, placed at__pπ«template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr iterator insert (const_iterator __p, _InputIterator __beg, _InputIterator __end)β insert a range of characters, and look at that_RequireInputIterconstraint, she's picky and she's right πconstexpr iterator insert (const_iterator __p, initializer_list< _CharT > __l)β insert an initializer_list of characters πΈconstexpr iterator insert (const_iterator __p, size_type __n, _CharT __c)β insert multiple characters,__ncopies of__cβ¨iterator insert (iterator __p, _CharT __c)β insert one character, non-constexprtwin, note it'siterator __pnotconst_iteratorπtemplate<class _InputIterator> void insert (iterator __p, _InputIterator __beg, _InputIterator __end)β insert a range of characters, twin β and no_RequireInputIteron this one, just plainclass _InputIteratorπ¦void insert (iterator __p, initializer_list< _CharT > __l)β insert an initializer_list of characters, twin πvoid insert (iterator __p, size_type __n, _CharT __c)β insert multiple characters, twin πconstexpr basic_string & insert (size_type __pos, const _CharT *__s)β insert a C string at__posπΈbasic_string & insert (size_type __pos, const _CharT *__s)β twin π¦constexpr basic_string & insert (size_type __pos, const _CharT *__s, size_type __n)β insert a C substring π«basic_string & insert (size_type __pos, const _CharT *__s, size_type __n)β twin πconstexpr basic_string & insert (size_type __pos, size_type __n, _CharT __c)β insert multiple characters β¨basic_string & insert (size_type __pos, size_type __n, _CharT __c)β twin πconstexpr basic_string & insert (size_type __pos1, const basic_string &__str)β insert value of a string, and yes the parameter is__pos1here πΈbasic_string & insert (size_type __pos1, const basic_string &__str)β twin π¦constexpr basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos)β insert a substring, four params deep and__n=nposby default π«basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos)β twin πconstexpr size_type length () const noexceptβ returns the number of characters in the string, not including any null-termination β the null-terminator does NOT get counted, bestie, she's not that kind of girl πsize_type length () const noexceptβ same count, non-constexprtwin πconstexpr size_type max_size () const noexceptβ returns thesize()of the largest possible string β the absolute biggest she could ever be π
and we are STILL not done, do not close the terminal, more overloads incoming ππ
size_type max_size () const noexceptβ tells you thesize()of the largest possible string. like, the absolute theoretical ceiling of string, bestie. you will never hit it. it's giving "max capacity, no cap" πconstexpr basic_string & operator+= (_CharT __c)β append a character β¨basic_string & operator+= (_CharT __c)β append a character (same thing, the runtime twin)constexpr basic_string & operator+= (const _CharT *__s)β append a C string πΈbasic_string & operator+= (const _CharT *__s)β append a C stringconstexpr basic_string & operator+= (const basic_string &__str)β append a whole string onto this string π«Άbasic_string & operator+= (const basic_string &__str)β append a string to this stringconstexpr basic_string & operator+= (initializer_list< _CharT > __l)β append aninitializer_listof characters πbasic_string & operator+= (initializer_list< _CharT > __l)β append aninitializer_listof charactersconstexpr basic_string & operator= (_CharT __c)β set the value to a string of length1π·basic_string & operator= (_CharT __c)β set value to string of length 1basic_string & operator= (basic_string &&__str) noexcept(/*conditional */)β move-assign the value ofstrinto this string πconstexpr basic_string & operator= (basic_string &&__str) noexcept(_Alloc_traits::_S_nothrow_move())β move assign the value of str to this stringconstexpr basic_string & operator= (const _CharT *__s)β copy the contents ofsinto this string β¨basic_string & operator= (const _CharT *__s)β copy contents of s into this stringconstexpr basic_string & operator= (const basic_string &__str)β assign the value ofstrto this string πbasic_string & operator= (const basic_string &__str)β assign the value of str to this stringconstexpr basic_string & operator= (initializer_list< _CharT > __l)β set the value to a string constructed from an initializer list πbasic_string & operator= (initializer_list< _CharT > __l)β set value to string constructed from initializer listbasic_string & operator= (nullptr_t)=deleteβ DELETED. not allowed, don't even try it, it's literally been erased from existence πbasic_string & operator= (nullptr_t)=deleteβ deleted (yes, again, that's the point)constexpr reference operator[] (size_type __pos)β subscript access to the data chillin' inside the string πreference operator[] (size_type __pos)β subscript access to the data contained in the stringconstexpr const_reference operator[] (size_type __pos) const noexceptβ theconstversion of that subscript access, same vibe π¦const_reference operator[] (size_type __pos) const noexceptβ subscript access to the data contained in the stringvoid pop_back ()β remove the last character. bye bestie πconstexpr void pop_back () noexceptβ remove the last characterconstexpr void push_back (_CharT __c)β append a single character πvoid push_back (_CharT __c)β append a single characterreverse_iterator rbegin ()β (no blurb given for this one, it just exists and does its thing) πconstexpr const_reverse_iterator rbegin () const noexceptβ (no blurb, but she's here)const_reverse_iterator rbegin () const noexceptβ (still no blurb, iconic silence)constexpr reverse_iterator rbegin () noexceptβ (no description supplied)reverse_iterator rend ()β (no blurb in the original, just vibes) β¨constexpr const_reverse_iterator rend () const noexceptβ (no blurb)const_reverse_iterator rend () const noexceptβ (no blurb)constexpr reverse_iterator rend () noexceptβ (no description given)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, _CharT *__k1, _CharT *__k2)β (no blurb for this overload, it's just there)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__k1, const _CharT *__k2)β (no blurb either)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s)β replace a range of characters with a C string πΈconstexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const _CharT *__s, size_type __n)β replace a range of characters with a C substring β¨constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const basic_string &__str)β replace a range of characters with a string πconstexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, const_iterator __k1, const_iterator __k2)β (no blurb)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, iterator __k1, iterator __k2)β (no blurb)constexpr basic_string & replace (__const_iterator __i1, __const_iterator __i2, size_type __n, _CharT __c)β replace a range of characters with multiple characters πtemplate<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, _InputIterator __k1, _InputIterator __k2)β replace a range of characters with a range π¦constexpr basic_string & replace (const_iterator __i1, const_iterator __i2, initializer_list< _CharT > __l)β replace a range of characters with aninitializer_listπbasic_string & replace (iterator __i1, iterator __i2, _CharT *__k1, _CharT *__k2)β (no blurb)template<class _InputIterator> basic_string & replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)β replace a range of characters with a range β¨basic_string & replace (iterator __i1, iterator __i2, const _CharT *__k1, const _CharT *__k2)β (no blurb)basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s)β replace a range of characters with a C string πΈbasic_string & replace (iterator __i1, iterator __i2, const _CharT *__s, size_type __n)β replace a range of characters with a C substringbasic_string & replace (iterator __i1, iterator __i2, const basic_string &__str)β replace a range of characters with a string πbasic_string & replace (iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2)β (no blurb)basic_string & replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l)β replace a range of characters with aninitializer_listπbasic_string & replace (iterator __i1, iterator __i2, iterator __k1, iterator __k2)β (no blurb)basic_string & replace (iterator __i1, iterator __i2, size_type __n, _CharT __c)β replace a range of characters with multiple characters π₯constexpr basic_string & replace (size_type __pos, size_type __n, const basic_string &__str)β replace characters with a value from another string π«Άbasic_string & replace (size_type __pos, size_type __n, const basic_string &__str)β replace characters with value from another stringconstexpr basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s)β replace characters with the value of a C string β¨basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s)β replace characters with value of a C stringconstexpr basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)β replace characters with the value of a C substring πbasic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)β replace characters with value of a C substringconstexpr basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c)β replace characters with multiple characters π·basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c)β replace characters with multiple charactersconstexpr basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos)β replace characters with a value from another string πbasic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos)β replace characters with value from another stringconstexpr void reserve ()β (no blurb for this one)void reserve ()β equivalent toshrink_to_fit()π§constexpr void reserve (size_type __res_arg)β try to preallocate enough memory for the specified number of characters πvoid reserve (size_type __res_arg)β attempt to preallocate enough memory for specified number of charactersconstexpr void resize (size_type __n)β resizes the string to the specified number of characters π¦void resize (size_type __n)β resizes the string to the specified number of charactersconstexpr void resize (size_type __n, _CharT __c)β resizes the string to the specified number of characters β¨void resize (size_type __n, _CharT __c)β resizes the string to the specified number of charactersconstexpr size_type rfind (_CharT __c, size_type __pos=npos) const noexceptβ find the last position of a character (reverse search, main character energy) πsize_type rfind (_CharT __c, size_type __pos=npos) const noexceptβ find last position of a characterconstexpr size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find the last position of a C substring πΈsize_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexceptβ find last position of a C substringconstexpr size_type rfind (const _CharT *__s, size_type __pos=npos) constβ find the last position of a C string πsize_type rfind (const _CharT *__s, size_type __pos=npos) const noexceptβ find last position of a C 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 last position of a stringconstexpr void shrink_to_fit () noexceptβ a non-binding request to shrinkcapacity()down tosize()β keyword non-binding, so it can absolutely ignore you πvoid shrink_to_fit () noexceptβ a non-binding request to reducecapacity()tosize()constexpr size_type size () const noexceptβ returns the number of characters in the string, not counting any null-termination πsize_type size () const noexceptβ returns the number of characters in the string, not including any null-terminationconstexpr bool starts_with (_CharT __x) const noexceptβ (no blurb given)bool starts_with (_CharT __x) const noexceptβ (no blurb)constexpr bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexceptβ (no blurb)bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexceptβ (no blurb)constexpr bool starts_with (const _CharT *__x) const noexceptβ (no blurb)bool starts_with (const _CharT *__x) const noexceptβ (no blurb)constexpr basic_string substr (size_type __pos, size_type __n) &&β (no blurb for this rvalue overload)constexpr basic_string substr (size_type __pos=0) &&β (no blurb)constexpr basic_string substr (size_type __pos=0, size_type __n=npos) constβ get a substring βοΈbasic_string substr (size_type __pos=0, size_type __n=npos) constβ get a substringconstexpr basic_string_view< _CharT, _Traits > subview (size_type __pos=0, size_type __n=npos) constβ get a subview πconstexpr basic_string_view< _CharT, _Traits > subview (size_type __pos=0, size_type __n=npos) constβ get a subview (yes, listed twice, that's the docs' business not mine)constexpr void swap (basic_string &__s) noexceptβ swap contents with another string πβ¨void swap (basic_string &__s) noexcept(/*conditional */)β trades contents with another string. Bestie swap, no cap. β¨
πΈ Static Public Attributes πΈ
static const size_type nposβ the iconic "nope, that didn't work" value. All the member functions that fail come back holding this. It's giving "not found, babe." π
π Protected Types π
typedef const_iterator __const_iteratortypedef iterator __const_iterator
(yes, it literally says that twice, and no, we are not editing the source, we respect the ancestors π)
π«Ά Friends π«Ά
template<typename, typename, typename> class basic_stringbuf
π Detailed Description π
template<typename _CharT, typename _Traits, typename _Alloc>
class std::basic_string< _CharT, _Traits, _Alloc >
Managing sequences of characters and character-like objects. That's the whole job. That's the assignment. β¨
Since: C++98 (an elder, a legend, a founding mother π«Ά)
Template Parameters
_CharTβ type of character_Traitsβ traits for character type, defaults tochar_traits<_CharT>_Allocβ allocator type, defaults toallocator<_CharT>
It meets the requirements of a container, a reversible container, and a sequence. And of the optional sequence requirements? Only push_back, at, and array access are supported. That's it. That's the list. Don't come for her about the others. π
Since: C++98
Template Parameters
_CharTβ type of character_Traitsβ traits for character type, defaults tochar_traits<_CharT>_Allocβ allocator type, defaults toallocator<_CharT>
It meets the requirements of a container, a reversible container, and a sequence. Of the optional sequence requirements, only push_back, at, and array access are supported. (Yep, the manpage says this whole thing twice. We are simply built different. We repeat ourselves. Periodt. π)
Todo β Needs documentation! See http://gcc.gnu.org/onlinedocs/libstdc++/manual/documentation_style.html
Documentation? What's that? Nathan Myers ncm@cantrip.org. β an absolute icon, honestly, the confidence, the audacity, the legacy. π
π¦ A string looks like this π¦
[_Rep]
_M_length
[basic_string<char_type>] _M_capacity
_M_dataplus _M_refcount
_M_p ----------------> unnamed array of char_type
Okay so let's decode the vibe check here. π
Where the _M_p points to the first character in the string, and you cast it to a pointer-to-_Rep and subtract 1 to get a pointer to the header. Yes bestie, we're doing pointer arithmetic before breakfast. π§
This approach has the enormous advantage that a string object requires only one allocation. All the ugliness is confined within a single pair of inline functions, which each compile to a single add instruction: _Rep::_M_data(), and string::_M_rep(); and the allocation function which gets a block of raw bytes and with room enough and constructs a _Rep object at the front. She's efficient. She's lowkey elegant. She ate. π₯
The reason you want _M_data pointing to the character array and not the _Rep is so that the debugger can see the string contents. (Probably we should add a non-inline member to get the _Rep for the debugger to use, so users can check the actual string length.) Not me exposing the debugger's whole situation like this π
Note that the _Rep object is a POD so that you can have a static empty string _Rep object already constructed before static constructors have run. The reference-count encoding is chosen so that a 0 indicates one reference, so you never try to destroy the empty-string _Rep object. It's giving "the empty string cannot be killed." Iconic. Untouchable. π
All but the last paragraph is considered pretty conventional for a Copy-On-Write C++ string implementation. β the last paragraph being the special one, the main character, the exception to the rule. π
π Constructor & Destructor Documentation π
okay bestie, this is the part where the string gets born πΌβ¨ and, spoiler, it also gets yeeted into the void at the end. Let's go one by one, no skips, no cap.
Also heads up: the page runs the whole set twice β once with the [constexpr] glow-up and once without. Both are here, fr fr, nothing dropped. π
πΈ the no-arg glow-up
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string () [inline], [constexpr], [noexcept]
Default constructor creates an empty string. an empty queen, a blank canvas, a whole mood π
Referenced by std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::substr(), and swap().
not me listing assign() twice β the manpage said it twice, so bestie, so do I. we do NOT drop duplicates. periodt.
π§ the "bring your own allocator" starter pack
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _Alloc & __a) [inline], [explicit], [constexpr], [noexcept]
Construct an empty string using allocator a.
note the [explicit] β it's giving "no sneaky implicit conversions, we're classy here" π
π¦ the copycat (iconic behaviour honestly)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]
Construct string with copy of value of __str.
Parameters
__strβ Source string.
π copy but make it a substring (pos only)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, const _Alloc & __a = _Alloc()) [inline], [constexpr]
Construct string as copy of a substring.
Parameters
__strβ Source string.__posβ Index of first character to copy from.__aβ Allocator to use.
π copy but make it a substring (pos + length)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n) [inline], [constexpr]
Construct string as copy of a substring.
Parameters
__strβ Source string.__posβ Index of first character to copy from.__nβ Number of characters to copy.
π the FULL send substring: pos + length + allocator
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n, const _Alloc & __a) [inline], [constexpr]
Construct string as copy of a substring.
Parameters
__strβ Source string.__posβ Index of first character to copy from.__nβ Number of characters to copy.__aβ Allocator to use.
π char array β string (length-based, '\0' is NOT special)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, size_type __n, const _Alloc & __a = _Alloc()) [inline], [constexpr]
Construct string initialized by a character array.
Parameters
__sβ Source character array.__nβ Number of characters to copy.__aβ Allocator to use (default is default allocator).
NB:__smust have at least__ncharacters,'\0'has no special meaning. bestie this is the important bit β it does NOT stop at the null terminator, it takes what you tell it to take. don't get caught slippin' π
β¨ C string β string (the '\0'-aware one)
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename = _RequireAllocator<_Alloc>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, const _Alloc & __a = _Alloc()) [inline], [constexpr]
Construct string as copy of a C string.
Parameters
__sβ Source C string.__aβ Allocator to use (default is default allocator).
π«Ά fill 'er up: n copies of one character
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename = _RequireAllocator<_Alloc>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (size_type __n, _CharT __c, const _Alloc & __a = _Alloc()) [inline], [constexpr]
Construct string as multiple characters.
Parameters
__nβ Number of characters.__cβ Character to use.__aβ Allocator to use (default is default allocator).
π₯ the MOVE constructor (steal the vibe, leave them guessing)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [constexpr], [noexcept]
Move construct string.
Parameters
__strβ Source string.
The newly-created string contains the exact contents of __str. __str is a valid, but unspecified string.
translation: new string ate everything π½οΈ, old string is still alive but it's giving "idk what I am anymore" β valid but unspecified, okay?? don't touch it and expect specific contents.
π initializer list, but make it a string
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (initializer_list< _CharT > __l, const _Alloc & __a = _Alloc()) [inline], [constexpr]
Construct string from an initializer list.
Parameters
__lβstd::initializer_listof characters.__aβ Allocator to use (default is default allocator).
π§ the iterator range one (beg to end, no cap)
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc & __a = _Alloc()) [inline], [constexpr]
Construct string as copy of a range.
Parameters
__begβ Start of range.__endβ End of range.__aβ Allocator to use (default is default allocator).
π and nowβ¦ the DESTRUCTOR (rip bozo)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::~basic_string () [inline], [constexpr]
Destroy the string instance.
she served her purpose, she's done, she's free now ποΈ
πΈ okay now the SAME constructors again, but the non-constexpr edition πΈ
same roster, different sparkle β¨
π default constructor (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string () [inline], [noexcept]
Default constructor creates an empty string.
π§ allocator constructor (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _Alloc & __a) [inline], [explicit]
Construct an empty string using allocator a.
π¦ copy constructor (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline]
Construct string with copy of value of str.
Parameters
__strβ Source string.
π substring, pos-only (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, const _Alloc & __a = _Alloc())
Construct string as copy of a substring.
Parameters
__strβ Source string.__posβ Index of first character to copy from.__aβ Allocator to use.
π substring, pos + n (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n)
Construct string as copy of a substring.
Parameters
__strβ Source string.__posβ Index of first character to copy from.__nβ Number of characters to copy.
π substring, pos + n + allocator (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n, const _Alloc & __a)
Construct string as copy of a substring.
Parameters
__strβ Source string.__posβ Index of first character to copy from.__nβ Number of characters to copy.__aβ Allocator to use.
π«Ά char array + length (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, size_type __n, const _Alloc & __a = _Alloc()) [inline]
Construct string initialized by a character array.
Parameters
__sβ Source character array.__nβ Number of characters to copy.__aβ Allocator to use (default is default allocator).
NB:__smust have at least__ncharacters,'\0'has no special meaning. still true, still important π
β¨ C string (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename = _RequireAllocator<_Alloc>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _CharT * __s, const _Alloc & __a = _Alloc()) [inline]
Construct string as copy of a C string.
Parameters
__sβ Source C string.__aβ Allocator to use (default is default allocator).
π n copies of a character (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (size_type __n, _CharT __c, const _Alloc & __a = _Alloc()) [inline]
Construct string as multiple characters.
Parameters
__nβ Number of characters.__cβ Character to use.__aβ Allocator to use (default is default allocator).
π₯ move constructor (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [noexcept]
Move construct string.
Parameters
__strβ Source string.
The newly-created string contains the exact contents of __str. __str is a valid, but unspecified string.
π initializer list (round two)
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (initializer_list< _CharT > __l, const _Alloc & __a = _Alloc()) [inline]
Construct string from an initializer list.
Parameters
__lβstd::initializer_listof characters.__aβ Allocator to use (default is default allocator).
π§ iterator range (round two, class template style)
template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc & __a = _Alloc()) [inline]
Construct string as copy of a range.
Parameters
__begβ Start of range.__endβ End of range.__aβ Allocator to use (default is default allocator).
π destructor (round two, this time it's [noexcept])
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_string< _CharT, _Traits, _Alloc >::~basic_string () [inline], [noexcept]
Destroy the string instance.
π Member Function Documentation π
and now we're in the member functions, bestie, strap in π
π§ __resize_and_overwrite β the double-underscore special
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _Operation>
void std::basic_string< _CharT, _Traits, _Alloc >::__resize_and_overwrite (size_type __n, _Operation __op) [constexpr]
Non-standard version of resize_and_overwrite for C++11 and above.
π§ __resize_and_overwrite β again, but non-constexpr
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _Operation>
void std::basic_string< _CharT, _Traits, _Alloc >::__resize_and_overwrite (size_type __n, _Operation __op)
Non-standard version of resize_and_overwrite for C++11 and above.
π¦ append β range edition (with the constexpr glow)
template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (_InputIterator __first, _InputIterator __last) [inline], [constexpr]
Append a range of characters.
Parameters
__firstβ Iterator referencing the first character to append.__lastβ Iterator marking the end of the range.
Returns
- Reference to this string.
Appends characters in the range [__first,__last) to this string.
π append β range edition (no constexpr, still iconic)
template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (_InputIterator __first, _InputIterator __last) [inline]
Append a range of characters.
β¦and that's where this part wraps, bestie β more member functions are waiting in the next chunk, don't go anywhere π«Ά
okay so that iterator-range append we just opened up β here's the rest of its paperwork, bestie π«Ά
__firstβ iterator referencing the first character to append β¨__lastβ iterator marking the end of the range π
Returns: a reference to this string, always, so you can chain these forever π
What it do: appends the characters in the range [__first,__last) to this string. that's the whole job. no cap πΈ
π₯ append β append a C string ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s) [inline], [constexpr]
Append a C string. yes, literally just yeet a whole C string onto the end π
__sβ the C string to append
Returns: reference to this string π
π₯ append β append a C string ([inline])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s) [inline]
the non-constexpr twin of the one above, same energy, same everything:
__sβ the C string to append
Returns: reference to this string π
π¦ append β append a C substring ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s, size_type __n) [inline], [constexpr]
Append a C substring β so, only part of the C string, because sometimes you don't want the whole thing π
__sβ the C string to append__nβ the number of characters to append
Returns: reference to this string π
π¦ append β append a C substring (no [inline]/[constexpr] tag)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT * __s, size_type __n)
Append a C substring. same deal as the one right above, just the other variant:
__sβ the C string to append__nβ the number of characters to append
Returns: reference to this string π
π append β append a string ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]
Append a string to this string. string-on-string action, iconic π
__strβ the string to append
Returns: reference to this string π
Referenced by:
std::basic_string< _CharT >::append()std::basic_string< _CharT >::append()std::basic_string< _CharT >::append()std::basic_string< _CharT >::append()std::__cxx11::collate< _CharT >::do_transform()std::basic_string< _CharT >::operator+=()std::basic_string< _CharT >::operator+=()std::basic_string< _CharT >::operator+=()std::operator>>()resize()
π append β append a string (other variant)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str)
Append a string to this string. the sibling of the one above, same facts:
__strβ the string to append
Returns: reference to this string π
π append β append a substring ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n = npos) [inline], [constexpr]
Append a substring β slice of a string, bestie, we're picking a starting point AND a length πͺβ¨
__strβ the string to append__posβ index of the first character of str to append__nβ the number of characters to append
Returns: reference to this string π
Exceptions:std::out_of_rangeif__posis not a valid index. so like, don't be messy with your indices, fr fr π
This function appends __n characters from __str starting at __pos to this string. And if __n is larger than the number of available characters in __str, the remainder of __str is appended. it just takes what it can get, main character energy π
π append β append a substring (other variant)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos, size_type __n = npos)
Append a substring. the matching non-constexpr/non-[inline] version:
__strβ the string to append__posβ index of the first character of str to append__nβ the number of characters to append
Returns: reference to this string π
Exceptions:std::out_of_rangeif__posis not a valid index. still true, still will ruin your day π
This function appends __n characters from __str starting at __pos to this string. If __n is larger than the number of available characters in __str, the remainder of __str is appended. same as above, exact same rules πΈ
π§ append β append an initializer_list ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (initializer_list< _CharT > __l) [inline], [constexpr]
Append an initializer_list of characters. curly-brace girlies, this one's for you π
__lβ theinitializer_listof characters to append
Returns: reference to this string π
π§ append β append an initializer_list ([inline])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (initializer_list< _CharT > __l) [inline]
Append an initializer_list of characters. the twin, same vibes:
__lβ theinitializer_listof characters to append
Returns: reference to this string π
π
append β append multiple characters ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::append (size_type __n, _CharT __c) [inline], [constexpr]
Append multiple characters β one character, repeated. the remix π΅
__nβ the number of characters to append__cβ the character to use
Returns: reference to this string π
Appends __n copies of __c to this string. yes, __n copies. count them. β
π
append β append multiple characters (other variant)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::append (size_type __n, _CharT __c)
Append multiple characters. the non-constexpr twin:
__nβ the number of characters to append__cβ the character to use
Returns: reference to this string π
Appends __n copies of __c to this string. still __n copies. still slaying π«Ά
π and nowβ¦ assign π
new function drop!! assign doesn't add to your string β it replaces the whole value. it's giving makeover episode π
π¦ assign β set value to a range of characters ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (_InputIterator __first, _InputIterator __last) [inline], [constexpr]
Set value to a range of characters π
__firstβ iterator referencing the first character to append__lastβ iterator marking the end of the range
Returns: reference to this string π
Sets value of string to characters in the range [__first,__last). so whatever was in there before? gone. replaced. glow-up complete β¨
π¦ assign β set value to a range of characters ([inline])
template<typename _CharT, typename _Traits, typename _Alloc> template<class _InputIterator> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (_InputIterator __first, _InputIterator __last) [inline]
Set value to a range of characters. the sibling overload, note it has no std::_RequireInputIter constraint in its template list π
__firstβ iterator referencing the first character to append__lastβ iterator marking the end of the range
Returns: reference to this string π
Sets value of string to characters in the range [__first,__last). same rules, same range, same energy πΈ
π assign β set value to contents of another string ([inline], [constexpr], [noexcept])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [constexpr], [noexcept]
Set value to contents of another string β and it's an rvalue ref, so we're moving, bestie ππ¨
__strβ source string to use
Returns: reference to this string π
This function sets this string to the exact contents of __str. And listen: __str is a valid, but unspecified string afterward. so don't go reading it and expecting your data back, it's been through something π
π assign β set value to contents of another string ([inline], [noexcept])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [noexcept]
Set value to contents of another string. the other variant, no [constexpr] tag on this one:
__strβ source string to use
Returns: reference to this string π
This function sets this string to the exact contents of __str. __str is a valid, but unspecified string. yes, still unspecified. still don't touch it π«£
π assign β set value to contents of a C string ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s) [inline], [constexpr]
Set value to contents of a C string π
__sβ the C string to use
Returns: reference to this string π
This function sets the value of this string to the value of __s. The data is copied, so there is no dependence on __s once the function returns. copied!! so you can do whatever you want to __s after, it's not your problem anymore π
π assign β set value to contents of a C string ([inline])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s) [inline]
Set value to contents of a C string. twin overload:
__sβ the C string to use
Returns: reference to this string π
This function sets the value of this string to the value of __s. The data is copied, so there is no dependence on __s once the function returns. still copied. still free π¦
π§ assign β set value to a C substring ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s, size_type __n) [inline], [constexpr]
Set value to a C substring βοΈ
__sβ the C string to use__nβ number of characters to use
Returns: reference to this string π
This function sets the value of this string to the first __n characters of __s. If __n is larger than the number of available characters in __s, the remainder of __s is used. it'll take what's there and not complain about it πΈ
π§ assign β set value to a C substring (other variant)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const _CharT * __s, size_type __n)
Set value to a C substring. the matching variant:
__sβ the C string to use__nβ number of characters to use
Returns: reference to this string π
This function sets the value of this string to the first __n characters of __s. If __n is larger than the number of available characters in __s, the remainder of __s is used. same rules, bestie, nothing new to learn here π«Ά
π assign β set value to contents of another string ([inline], [constexpr])
template<typename _CharT, typename _Traits, typename _Alloc> basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc >::assign (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]
Set value to contents of another string β this time it's the const-ref one, so a copy, not a move π―
__strβ source string to use
Returns: reference to this string π
Referenced by:
std::basic_string< _CharT >::assign()std::basic_string< _CharT >::assign()std::basic_string< _CharT >::assign()std::basic_string< _CharT >::operator=()std::basic_string< _CharT >::operator=()std::basic_string< _CharT >::operator=()std::basic_string< _CharT >::operator=()std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow()std::basic_stringbuf< char >::str()std::basic_stringbuf< char >::str()
π assign β set value to contents of another string
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign (const basic_string< _CharT, _Traits, _Alloc > & __str)
Set value to contents of another string. the last one in this batch:
__strβ source string to use
Returns: reference to this string π
π«Ά assign β set this string to a substring of another string π«Ά
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos,
size_type __n = npos) [inline], [constexpr]
okay bestie so this one is literally "become a slice of somebody else's string". We're in the constexpr era here, slay β¨
- Parameters
__strβ the string we're stealing from π__posβ index of the first character ofstr__nβ how many characters we're taking
- Returns β a reference to this string (so you can chain, iconic)
- Exceptions β
std::out_of_rangeifposis not a valid index π
The lore: this function sets this string to the substring of __str consisting of __n characters at __pos. And if __n is is larger than the number of available characters in __str, the remainder of __str is used. (yes, "is is", we do not gatekeep typos in this house π)
π assign β same thing, but the classic cut π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos,
size_type __n = npos) [inline]
Same assignment, no constexpr tag on this one. Set value to a substring of a string, fr fr.
- Parameters
__strβ the string to use.__posβ index of the first character ofstr.__nβ number of characters to use.
- Returns β reference to this string π«Ά
- Exceptions β
std::out_of_rangeifposis not a valid index.
This function sets this string to the substring of __str consisting of __n characters at __pos. If __n is is larger than the number of available characters in __str, the remainder of __str is used. Same energy, different vibe check β¨
π¦ assign β from an initializer_list π¦
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(initializer_list< _CharT > __l) [inline], [constexpr]
Set value to an initializer_list of characters. Curly braces girlies rise πΈ
- Parameters β
__lβ theinitializer_listof characters to assign. - Returns β reference to this string. π
π§ assign β same, the non-constexpr twin π§
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(initializer_list< _CharT > __l) [inline]
Set value to an initializer_list of characters.
- Parameters β
__lβ theinitializer_listof characters to assign. - Returns β reference to this string. π
π₯ assign β fill me with N copies of a character π₯
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(size_type __n, _CharT __c) [inline], [constexpr]
Set value to multiple characters. You want a string that's just 'x' a hundred times? She's got you, no cap.
- Parameters
__nβ length of the resulting string.__cβ the character to use.
- Returns β reference to this string. π
This function sets the value of this string to __n copies of character __c. That's it, that's the whole thing, periodt.
π assign β the duplicate, but make it classic π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(size_type __n, _CharT __c) [inline]
Set value to multiple characters.
- Parameters
__nβ length of the resulting string.__cβ the character to use.
- Returns β reference to this string.
This function sets the value of this string to __n copies of character __c. π
β at β the safe one, read/write edition β
template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::at (size_type __n)
[inline], [nodiscard], [constexpr]
Provides access to the data contained in the string. Bounds-checked access, the responsible main character π«Ά
- Parameters β
__nβ the index of the character to access. - Returns β read/write reference to the character.
- Exceptions β
std::out_of_rangeifnis an invalid index. π
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. We love a function that checks before it vibes.
πΈ at β safe, and also unshares πΈ
template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::at (size_type __n)
[inline]
Provides access to the data contained in the string.
- Parameters β
__nβ the index of the character to access. - Returns β read/write reference to the character.
- Exceptions β
std::out_of_rangeifnis an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. Success results in unsharing the string. noted bestie π
π
at β const version, no touching π
template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::at
(size_type __n) const [inline], [nodiscard], [constexpr]
Provides access to the data contained in the string. Read-only, hands off, look but don't touch π
- Parameters β
__nβ the index of the character to access. - Returns β read-only (
const) reference to the character. - Exceptions β
std::out_of_rangeifnis an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. π
π¦ at β const, classic cut π¦
template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::at
(size_type __n) const [inline]
Provides access to the data contained in the string.
- Parameters β
__nβ the index of the character to access. - Returns β read-only (
const) reference to the character. - Exceptions β
std::out_of_rangeifnis an invalid index.
This function provides for safer data access. The parameter is first checked that it is in the range of the string. The function throws out_of_range if the check fails. β¨
π back β the last character, and you can edit her π
template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::back () [inline]
Returns a read/write reference to the data at the last element of the string. The final girl, literally πΈ
π§ back β const, nodiscard, constexpr, noexcept π§
template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::back () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reference to the data at the last element of the string. She cannot be changed, she is simply iconic π
π back β const, noexcept, that's the list π
template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string< _CharT, _Traits, _Alloc >::back () const
[inline], [noexcept]
Returns a read-only (constant) reference to the data at the last element of the string. π«Ά
π back β read/write, fully decked out in attributes π
template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string< _CharT, _Traits, _Alloc >::back ()
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read/write reference to the data at the last element of the string. Go ahead, change the last letter, she won't tell anyone π
π₯ begin β iterator to the very first character π₯
template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string< _CharT, _Traits, _Alloc >::begin () [inline]
Returns a read/write iterator that points to the first character in the string. Unshares the string. Important, don't skip that part bestie.
β begin β const, nodiscard, constexpr, noexcept β
template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::begin () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) iterator that points to the first character in the string. π¦
π begin β const, noexcept π
template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::begin () const
[inline], [noexcept]
Returns a read-only (constant) iterator that points to the first character in the string. π
πΈ begin β read/write, and referenced by everyone πΈ
template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string< _CharT, _Traits, _Alloc >::begin ()
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read/write iterator that points to the first character in the string.
Referenced by std::basic_string< _CharT >::crend(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::regex_match(), std::regex_match(), std::regex_replace(), std::regex_replace(), std::regex_search(), std::basic_string< _CharT >::rend(), std::basic_string< _CharT >::rend(), std::basic_string< _CharT >::rend(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), and std::basic_string< _CharT >::replace().
Look at her, she's the moment, everyone's pulling up to her party πβ¨
π c_str β const pointer to null-terminated contents π
template<typename _CharT, typename _Traits, typename _Alloc>
const _CharT * std::basic_string< _CharT, _Traits, _Alloc >::c_str () const
[inline], [nodiscard], [constexpr], [noexcept]
Return const pointer to null-terminated contents. This is a handle to internal data. Do not modify or dire things may happen. bestie. DO NOT MODIFY. dire things. we mean it. π
Referenced by std::__cxx11::collate< _CharT >::do_compare(), std::money_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::__cxx11::collate< _CharT >::do_transform(), std::basic_filebuf< char_type, traits_type >::open(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::regex_replace(), and std::regex_traits< _CharT >::transform_primary().
π§ c_str β same deal, no constexpr tag π§
template<typename _CharT, typename _Traits, typename _Alloc>
const _CharT * std::basic_string< _CharT, _Traits, _Alloc >::c_str () const
[inline], [noexcept]
Return const pointer to null-terminated contents. This is a handle to internal data. Do not modify or dire things may happen. Still true, still scary, still not a drill π
π capacity β how many characters before we need more memory π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::capacity () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns the total number of characters that the string can hold before needing to allocate more memory. She's got room, she's just not telling you how much of it she's using π
Referenced by std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::push_back(), reserve(), and reserve().
π capacity β classic, noexcept only π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string< _CharT, _Traits, _Alloc >::capacity () const
[inline], [noexcept]
Returns the total number of characters that the string can hold before needing to allocate more memory. Same numbers, fewer tags, still slaying β¨
π¦ cbegin β const iterator to the first character π¦
template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::cbegin () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) iterator that points to the first character in the string. The c stands for "const, bestie, calm down" π
π cbegin β the other one, no constexpr π
template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::cbegin () const
[inline], [noexcept]
Returns a read-only (constant) iterator that points to the first character in the string. π«Ά
β cend β const iterator, one past the last character β
template<typename _CharT, typename _Traits, typename _Alloc>
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::cend () const
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) iterator that points one past the last character in the string. Yes, one past the last β that's the whole point of an end iterator, she's the afterparty, not a guest πΈ
π« cend()
template<typename _CharT, typename _Traits, typename _Alloc> const_iterator
std::basic_string< _CharT, _Traits, _Alloc >::cend () const
Attributes: [inline], [noexcept]
ok so cend() is the read-only bestie of end(). It hands you a constant iterator that points one past the last character in the string. That's it, that's the whole job β it's the "nothing to see here, and also don't touch anything" iterator. π
Reminder bestie: "one past the last character" means you can never dereference it. It's a fence post, not a sheep. π
π§Ή clear() β the constexpr edition
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::clear ()
Attributes: [inline], [constexpr], [noexcept]
Erases the string. Makes it empty. Poof, gone, nothing left, the string is now a whole vibe of void. β¨
Referenced by std::__cxx11::collate< _CharT >::do_transform(), and std::basic_string< _CharT >::operator=().
π§Ή clear() β the non-constexpr edition
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::clear ()
Attributes: [inline], [noexcept]
Same exact energy, just without the constexpr sparkle. Erases the string, making it empty. π
βοΈ compare() vs a C string β version one
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (const _CharT *
__s) const
Attributes: [inline], [nodiscard], [constexpr], [noexcept]
Compare to a C string. π¦
Parameters
__sβ C string to compare against.
Returns
- Integer
< 0,0, or> 0.
Returns an integer < 0 if this string is ordered before __s, 0 if their values are equivalent, or > 0 if this string is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of size() and the length of a string constructed from __s. The function then compares the two strings by calling traits::compare(data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π
βοΈ compare() vs a C string β version two
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (const _CharT *
__s) const
Attributes: [inline], [noexcept]
Compare to a C string. Same deal, no nodiscard, no constexpr. π
Parameters
__sβ C string to compare against.
Returns
- Integer
< 0,0, or> 0.
Returns an integer < 0 if this string is ordered before __s, 0 if their values are equivalent, or > 0 if this string is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of size() and the length of a string constructed from __s. The function then compares the two strings by calling traits::compare(data(),s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.
πͺ compare() vs a string β version one
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (const
basic_string< _CharT, _Traits, _Alloc > & __str) const
Attributes: [inline], [nodiscard], [constexpr]
Compare to a string. π
Parameters
__strβ String to compare against.
Returns
- Integer
< 0,0, or> 0.
Returns an integer < 0 if this string is ordered before __str, 0 if their values are equivalent, or > 0 if this string is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of size() and str.size(). The function then compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. β
πͺ compare() vs a string β version two
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (const
basic_string< _CharT, _Traits, _Alloc > & __str) const
Attributes: [inline]
Compare to a string. Yep, the bare-bones twin. πΈ
Parameters
__strβ String to compare against.
Returns
- Integer
< 0,0, or> 0.
Returns an integer < 0 if this string is ordered before __str, 0 if their values are equivalent, or > 0 if this string is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of size() and str.size(). The function then compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.
βοΈ compare() β substring vs a string, version one
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
const
Attributes: [inline], [nodiscard], [constexpr]
Compare substring to a string. Now we're getting fancy. π§
Parameters
__posβ Index of first character of substring.__nβ Number of characters in substring.__strβ String to compare against.
Returns
- Integer
< 0,0, or> 0.
Form the substring of this string from the __n characters starting at __pos. Returns an integer < 0 if the substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). The function then compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. π«
βοΈ compare() β substring vs a string, version two
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
const
Attributes: [inline]
Compare substring to a string. The un-sprinkled one. π
Parameters
__posβ Index of first character of substring.__nβ Number of characters in substring.__strβ String to compare against.
Returns
- Integer
< 0,0, or> 0.
Form the substring of this string from the __n characters starting at __pos. Returns an integer < 0 if the substring is ordered before __str, 0 if their values are equivalent, or > 0 if the substring is ordered after __str. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and __str.size(). The function then compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.
πΏ compare() β substring vs a C string, version one
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s) const
Attributes: [inline], [nodiscard], [constexpr]
Compare substring to a C string. π¦
Parameters
__posβ Index of first character of substring.__n1β Number of characters in substring.__sβ C string to compare against.
Returns
- Integer
< 0,0, or> 0.
Form the substring of this string from the __n1 characters starting at pos. Returns an integer < 0 if the substring is ordered before __s, 0 if their values are equivalent, or > 0 if the substring is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and the length of a string constructed from __s. The function then compares the two string by calling traits::compare(substring.data(),__s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. β¨
πΏ compare() β substring vs a C string, version two
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s) const
Attributes: [inline]
Compare substring to a C string. Again, the plain twin. π
Parameters
__posβ Index of first character of substring.__n1β Number of characters in substring.__sβ C string to compare against.
Returns
- Integer
< 0,0, or> 0.
Form the substring of this string from the __n1 characters starting at pos. Returns an integer < 0 if the substring is ordered before __s, 0 if their values are equivalent, or > 0 if the substring is ordered after __s. Determines the effective length rlen of the strings to compare as the smallest of the length of the substring and the length of a string constructed from __s. The function then compares the two string by calling traits::compare(substring.data(),__s,rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first.
π€ compare() β substring vs a character array, version one
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s, size_type __n2) const
Attributes: [inline], [nodiscard], [constexpr]
Compare substring against a character array. No null terminator energy here, just vibes and a length. π₯
Parameters
__posβ Index of first character of substring.__n1β Number of characters in substring.__sβ character array to compare against.__n2β Number of characters 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. π¨ bestie this one is serious β that null byte is NOT gonna save you here, it's just a regular character like everybody else. π
π€ compare() β substring vs a character array, version two
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s, size_type __n2) const
Attributes: [inline]
Compare substring against a character array. Same function, fewer attributes, same rules. π
Parameters
__posβ Index of first character of substring.__n1β Number of characters in substring.__sβ character array to compare against.__n2β Number of characters 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. π¨ Still true, still not joking around. π
π compare() β substring vs a substring
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos1,
size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos2, size_type __n2 = npos) const
Attributes: [inline], [nodiscard], [constexpr]
Compare substring to a substring. π
Parameters
__pos1β index of the first character of the substring π«Ά__n1β how many characters are in the substring__strβ the string we're comparing against, bestie__pos2β index of the first character of the substring of str__n2β number of characters in that substring of str
Returns
Integer < 0, 0, or > 0. (classic three-way comparison, she ate)
Form the substring of this string from the __n1 characters starting at __pos1. Form the substring of __str from the __n2 characters starting at __pos2. Returns an integer < 0 if this substring is ordered before the substring of __str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of __str. Determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. The function then compares the two strings by calling
traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen)
If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first. so simple, so iconic β¨
Compare substring to a substring πΈ
template<typename _CharT, typename _Traits, typename _Alloc> int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos1,
size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos2, size_type __n2 = npos) const [inline]
Compare substring to a substring. Yeah, she's back for round two, no cap π
Parameters
__pos1β index of the first character of the substring__n1β number of characters in the substring__strβ the string to compare against__pos2β index of the first character of the substring of str__n2β number of characters in the substring of str
Returns
Integer < 0, 0, or > 0.
Form the substring of this string from the __n1 characters starting at __pos1. Form the substring of __str from the __n2 characters starting at __pos2. Returns an integer < 0 if this substring is ordered before the substring of __str, 0 if their values are equivalent, or > 0 if this substring is ordered after the substring of __str. Determines the effective length rlen of the strings to compare as the smallest of the lengths of the substrings. The function then compares the two strings by calling
traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen)
If the result of the comparison is nonzero it returns it, otherwise the shorter one is ordered first.
copy β copy substring into a C string π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc >::size_type std::basic_string< _CharT, _Traits,
_Alloc >::copy (_CharT * __s, size_type __n, size_type __pos = 0) const
[constexpr]
Parameters
__sβ the C string you're copying the value into__nβ number of characters to copy__posβ index of the first character to copy
Returns
Number of characters actually copied. (yes, actually β she keeps it real)
Exceptions
std::out_of_rangeβ if__pos>size().
Copies up to __n characters starting at __pos into the C string __s. If __pos is greater than size(), out_of_range is thrown. so if you're out here passing a position past the end, she WILL throw, and honestly? deserved.
copy (the non-constexpr twin) π
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::copy (_CharT * __s,
size_type __n, size_type __pos = 0) const
Copy substring into C string.
Parameters
__sβ C string to copy value into__nβ number of characters to copy__posβ index of first character to copy
Returns
Number of characters actually copied
Exceptions
std::out_of_rangeβ if__pos>size().
Copies up to __n characters starting at __pos into the C string __s. If __pos is greater than size(), out_of_range is thrown.
crbegin β reverse iterator, but make it read-only π¦
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::crbegin () const [inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reverse iterator that points to the last character in the string. Iteration is done in reverse element order. walking backwards through your string, but respectfully and with no editing privileges π
crbegin (again, minus the sparkle tags)
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::crbegin () const [inline], [noexcept]
Returns a read-only (constant) reverse iterator that points to the last character in the string. Iteration is done in reverse element order.
crend β the other end of the reverse walk π
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::crend () const [inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order.
crend (the other other one) β¨
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::crend () const [inline], [noexcept]
Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order.
data β gimme that pointer π«Ά
template<typename _CharT, typename _Traits, typename _Alloc> const _CharT *
std::basic_string< _CharT, _Traits, _Alloc >::data () const [inline],
[nodiscard], [constexpr], [noexcept]
Return const pointer to contents. This is a pointer to internal data. It is undefined to modify the contents through the returned pointer. To get a pointer that allows modifying the contents use &str[0] instead, (or in C++17 the non-const str.data() overload).
okay bestie listen β DO NOT write through this pointer. it's giving "const for a reason." if you touch the bytes you're in undefined behaviour territory and she did not consent π
Referenced by std::basic_regex< char >::assign(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::__cxx11::collate< _CharT >::do_compare(), std::__cxx11::collate< _CharT >::do_transform(), std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find_first_not_of(), std::basic_string< _CharT >::find_first_of(), std::basic_string< _CharT >::find_last_of(), std::match_results< _BidirectionalIterator, polymorphic_allocator< sub_match< _BidirectionalIterator > > >< const char * >::format(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::from_bytes(), std::operator==(), std::basic_stringbuf< char >::str(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::to_bytes(), and std::regex_traits< _CharT >::transform(). she's popular, she's booked, she's everywhere fr fr
data (const edition, no frills)
template<typename _CharT, typename _Traits, typename _Alloc> const _CharT *
std::basic_string< _CharT, _Traits, _Alloc >::data () const [inline],
[noexcept]
Return const pointer to contents. This is a pointer to internal data. It is undefined to modify the contents through the returned pointer. To get a pointer that allows modifying the contents use &str[0] instead, (or in C++17 the non-const str.data() overload).
data β now non-const, now editable π
template<typename _CharT, typename _Traits, typename _Alloc> _CharT *
std::basic_string< _CharT, _Traits, _Alloc >::data () [inline],
[nodiscard], [constexpr], [noexcept]
Return non-const pointer to contents. This is a pointer to the character sequence held by the string. Modifying the characters in the sequence is allowed. glow up unlocked β¨
data (non-const, plain) πΈ
template<typename _CharT, typename _Traits, typename _Alloc> _CharT *
std::basic_string< _CharT, _Traits, _Alloc >::data () [inline]
Return non-const pointer to contents. This is a pointer to the character sequence held by the string. Modifying the characters in the sequence is allowed.
The standard requires this function to be noexcept but for the Copy-On-Write string implementation it can throw. This function allows modifying the string contents directly, which means we must copy-on-write to unshare it, which requires allocating memory.
and there it is β the plot twist. the standard says noexcept, but COW strings said "not today." if you're on a COW implementation, that innocent-looking call can allocate, and allocating can throw. iykyk π
empty β is it giving nothing? π
template<typename _CharT, typename _Traits, typename _Alloc> bool
std::basic_string< _CharT, _Traits, _Alloc >::empty () const [inline],
[nodiscard], [constexpr], [noexcept]
Returns true if the string is empty. Equivalent to *this == "".
Referenced by std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::front(), std::basic_string< _CharT >::front(), std::basic_string< _CharT >::front(), std::regex_traits< _Ch_type >::lookup_collatename(), std::tr2::operator>>(), std::basic_string< _CharT >::pop_back(), and std::basic_string< _CharT >::pop_back().
empty (again, for the people in the back) π
template<typename _CharT, typename _Traits, typename _Alloc> bool
std::basic_string< _CharT, _Traits, _Alloc >::empty () const [inline],
[nodiscard], [noexcept]
Returns true if the string is empty. Equivalent to *this == "".
end β the classic one-past-the-end π¦
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::end () [inline]
Returns a read/write iterator that points one past the last character in the string. Unshares the string. (yes girl, that means it might do COW things behind your back π)
end (const, fully decked out)
template<typename _CharT, typename _Traits, typename _Alloc> const_iterator
std::basic_string< _CharT, _Traits, _Alloc >::end () const [inline],
[nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) iterator that points one past the last character in the string.
end (const, minimal)
template<typename _CharT, typename _Traits, typename _Alloc> const_iterator
std::basic_string< _CharT, _Traits, _Alloc >::end () const [inline],
[noexcept]
Returns a read-only (constant) iterator that points one past the last character in the string.
end (non-const, decorated) π
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::end () [inline],
[nodiscard], [constexpr], [noexcept]
Returns a read/write iterator that points one past the last character in the string.
Referenced by std::basic_string< _CharT >::append(), std::basic_string< _CharT >::crbegin(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::erase(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::rbegin(), std::basic_string< _CharT >::rbegin(), std::basic_string< _CharT >::rbegin(), std::regex_match(), std::regex_match(), std::regex_replace(), std::regex_replace(), std::regex_search(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), and std::basic_string< _CharT >::replace(). the way literally every algorithm needs her... main character energy, no notes π
erase β remove a range of characters π₯
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::erase (__const_iterator
__first, __const_iterator __last) [inline], [constexpr]
Remove a range of characters.
Parameters
__firstβ iterator referencing the first character to remove__lastβ iterator referencing the end of the range
Returns
Iterator referencing location of first after removal.
Removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. strong exception guarantee, she's safe, she's stable, she's that girl π
erase β remove one character π
template<typename _CharT, typename _Traits, typename _Alloc> iterator
std::basic_string< _CharT, _Traits, _Alloc >::erase (__const_iterator
__position) [inline], [constexpr]
Remove one character.
Parameters
__positionβ iterator referencing the character to remove
Returns β iterator referencing same location after removal. π«
Removes the character at __position from this string. The value of the string doesn't change if an error is thrown. No cap, your string stays exactly as it was if something goes sideways.
π
iterator erase(iterator __first, iterator __last)
Remove a range of characters. bye-bye besties, a whole squad of them π«Ά
Parameters
__firstβ Iterator referencing the first character to remove.__lastβ Iterator referencing the end of the range.
Returns
- Iterator referencing location of first after removal.
Removes the characters in the range [first,last) from this string. The value of the string doesn't change if an error is thrown. Obsessed with how safe this is ngl.
β¨ iterator erase(iterator __position) [inline]
Remove one character. just the one, a lil solo moment π
Parameters
__positionβ Iterator referencing the character to remove.
Returns
iteratorreferencing same location after removal.
Removes the character at __position from this string. The value of the string doesn't change if an error is thrown. π
πΈ basic_string & erase(size_type __pos = 0, size_type __n = npos) [inline], [constexpr]
Remove characters. the index-based edition, very demure, very mindful
Parameters
__posβ Index of first character to remove (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. π¨
Removes __n characters from this string starting at __pos. The length of the string is reduced by __n. If there are < __n characters to remove, the remainder of the string is truncated. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown. Translation: it either fully does the thing or fully doesn't, no half-finished chaos here.
Referenced by std::getline(), std::operator>>(), std::basic_string< _CharT >::pop_back(), and resize(). π
π basic_string & erase(size_type __pos = 0, size_type __n = npos) [inline]
Remove characters. same energy, different flag set β¨
Parameters
__posβ Index of first character to remove (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. π¨
Removes __n characters from this string starting at __pos. The length of the string is reduced by __n. If there are < __n characters to remove, the remainder of the string is truncated. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown. π
π¦ size_type find(_CharT __c, size_type __pos = 0) const [nodiscard], [constexpr], [noexcept]
Find position of a character. where u at girl π
Parameters
__cβ Character to locate.__posβ Index of character to search from (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. And yes bestie, [nodiscard] means the compiler WILL side-eye you if you ignore the answer. Don't do it.
References npos, and std::size().
β size_type find(_CharT __c, size_type __pos = 0) const [noexcept]
Find position of a character. the remix π
Parameters
__cβ Character to locate.__posβ Index of character to search from (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. π
π₯ size_type find(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]
Find position of a C substring. C-string coded but make it specific
Parameters
__sβ C string to locate.__posβ Index of character to search from.__nβ Number of characters 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. π
References std::data(), npos, and std::size().
Referenced by std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find(), and std::basic_string< _CharT >::find_first_of(). (yes, find() shows up three times, she's popular, iykyk)
π§ size_type find(const _CharT * __s, size_type __pos, size_type __n) const [noexcept]
Find position of a C substring. encore β¨
Parameters
__sβ C string to locate.__posβ Index of character to search from.__nβ Number of characters 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. π¦
π size_type find(const _CharT * __s, size_type __pos = 0) const [inline], [nodiscard], [constexpr], [noexcept]
Find position of a C string. the whole string, no slicing required
Parameters
__sβ C string to locate.__posβ Index of character to search from (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. π
πΈ size_type find(const _CharT * __s, size_type __pos = 0) const [inline], [noexcept]
Find position of a C string. ok and again for the people in the back π£
Parameters
__sβ C string to locate.__posβ Index of character to search from (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. π
π size_type find(const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const [inline], [nodiscard], [constexpr], [noexcept]
Find position of a string. string looking for string, so meta π
Parameters
__strβ String to locate.__posβ Index of character to search from (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. β
π size_type find(const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const [inline], [noexcept]
Find position of a string. the twin, no [nodiscard] invited to this one
Parameters
__strβ String to locate.__posβ Index of character to search from (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. π
π size_type find_first_not_of(_CharT __c, size_type __pos = 0) const [nodiscard], [constexpr], [noexcept]
Find position of a different character. not like the other girls π
Parameters
__cβ Character to avoid.__posβ Index of character to search from (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. Basically: "first one that isn't this one, please."
References npos, and std::size().
β¨ size_type find_first_not_of(_CharT __c, size_type __pos = 0) const [noexcept]
Find position of a different character. round two, still not like the others π«
Parameters
__cβ Character to avoid.__posβ Index of character to search from (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. π
π¦ size_type find_first_not_of(const _CharT * __s, size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]
Find position of a character not in C substring. a whole lil C-string of characters to avoid, dramatic π
Parameters
__sβ C string containing characters to avoid.__posβ Index of character to search from.__nβ Number of characters from__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. π₯
References npos, and std::size().
π size_type find_first_not_of(const _CharT * __s, size_type __pos, size_type __n) const [noexcept]
Find position of a character not in C substring. same quest, different tag
Parameters
__sβ C string containing characters to avoid.__posβ Index of character to search from.__nβ Number of characters from__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. π
πΈ size_type find_first_not_of(const _CharT * __s, size_type __pos = 0) const [inline], [nodiscard], [constexpr], [noexcept]
Find position of a character not in C string. the whole C-string this time, no __n needed
Parameters
__sβ C string containing characters to avoid.__posβ Index of character to search from (default0).
β¦and that index is the index of the first occurrence. π
find_first_not_of β the C-string edition
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_not_of(const _CharT *__s, size_type __pos = 0) const
[inline], [noexcept]
Find position of a character not in C string. β¨
Parameters
__sβ the C string holding all the characters you want to avoid, bestie. Like a little list of nopes. π__posβ index of the character to start searching from (defaults to0, so like, the very beginning).
Returns
Index of first occurrence.
So starting from __pos, it searches forward for a character that is not contained in __s within this string. Found one? Slay, it hands you back the index where it lives. Not found? You get npos. π
find_first_not_of β the basic_string edition (the constexpr one π)
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const
[inline], [nodiscard], [constexpr], [noexcept]
Find position of a character not in string. π¦
Parameters
__strβ the string containing the characters to avoid.__posβ index of character to search from (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 by std::basic_string< _CharT >::find_first_not_of(), std::basic_string< _CharT >::find_first_not_of(), and std::basic_string< _CharT >::find_first_not_of().
find_first_not_of β the basic_string edition (non-constexpr twin)
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const
[inline], [noexcept]
Find position of a character not in string. πΈ
Parameters
__strβ string containing characters to avoid.__posβ index of character to search from (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_of β single char, constexpr girlie π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(_CharT __c, size_type __pos = 0) const
[inline], [nodiscard], [constexpr], [noexcept]
Find position of a character. β
Parameters
__cβ the character to locate.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for the character __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to find(__c, __pos). same thing, different font. π
find_first_of β single char, the other one
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(_CharT __c, size_type __pos = 0) const
[inline], [noexcept]
Find position of a character. π
Parameters
__cβ Character to locate.__posβ Index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for the character __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to find(__c, __pos).
find_first_of β C substring, constexpr edition
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos, size_type __n) const
[nodiscard], [constexpr], [noexcept]
Find position of a character of C substring. π₯
Parameters
__sβ string containing characters to locate.__posβ index of character to search from.__nβ number of characters fromsto search for.
Returns
Index of first occurrence.
Starting from __pos, searches forward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
References npos, and std::size().
find_first_of β C substring, non-constexpr twin
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos, size_type __n) const
[noexcept]
Find position of a character of C substring. π§
Parameters
__sβ string containing characters to locate.__posβ index of character to search from.__nβ number of characters fromsto search for.
Returns
Index of first occurrence.
Starting from __pos, searches forward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_of β whole C string, constexpr
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos = 0) const
[inline], [nodiscard], [constexpr], [noexcept]
Find position of a character of C string. π
Parameters
__sβ string containing characters to locate.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_of β whole C string, the twin
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const _CharT *__s, size_type __pos = 0) const
[inline], [noexcept]
Find position of a character of C string. π
Parameters
__sβ string containing characters to locate.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
find_first_of β basic_string flavor, constexpr girlie
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const
[inline], [nodiscard], [constexpr], [noexcept]
Find position of a character of string. β¨
Parameters
__strβ string containing characters to locate.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.
Referenced by std::basic_string< _CharT >::find_first_of(), and std::basic_string< _CharT >::find_first_of().
find_first_of β basic_string flavor, the twin
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_first_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = 0) const
[inline], [noexcept]
Find position of a character of string. πΈ
Parameters
__strβ string containing characters to locate.__posβ index of character to search from (default0).
Returns
Index of first occurrence.
Starting from __pos, searches forward for one of the characters of __str within this string. If found, returns the index where it was found. If not found, returns npos.
find_last_not_of β single char, searching backwards π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(_CharT __c, size_type __pos = npos) const
[nodiscard], [constexpr], [noexcept]
Find last position of a different character. π
Parameters
__cβ character to avoid.__posβ index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.
References npos, and std::size().
find_last_not_of β single char, the twin
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(_CharT __c, size_type __pos = npos) const
[noexcept]
Find last position of a different character. π¦
Parameters
__cβ character to avoid.__posβ index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character other than __c within this string. If found, returns the index where it was found. If not found, returns npos.
find_last_not_of β C substring, constexpr edition
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos, size_type __n) const
[nodiscard], [constexpr], [noexcept]
Find last position of a character not in C substring. π₯
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search back from.__nβ number of characters 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 β C substring, the twin
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos, size_type __n) const
[noexcept]
Find last position of a character not in C substring. π§
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search back from.__nβ number of characters 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.
find_last_not_of β whole C string, constexpr edition
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character not in C string. π
Parameters
__sβ C string containing characters to avoid.__posβ index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for a character not contained in __s within this string. If found, returns the index where it was found. If not found, returns npos.
πΈ find_last_not_of β the "who here is NOT on the list" detector
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const _CharT *__s, size_type __pos = npos) const
[inline], [noexcept]
Find last position of a character not in C string.
Parameters
__sβ a C string stuffed with the characters you wanna avoid, bestie.__posβ the index of the character you start searching back from (default is the end,npos).
Returns
Index of the last occurrence. π
okay so real talk: it starts at __pos and walks backward through this string, hunting for a character that is not contained in __s. Found one? Slay, it returns the index where it lives. Not found? It hands you npos and you gotta deal with it. π
β¨ find_last_not_of β string version (the fancy one)
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character not in string.
Parameters
__strβ the string holding all the characters you're avoiding.__posβ index of the character to search back from (default is the end).
Returns
Index of the last occurrence. π
Starting from __pos, it searches backward for a character that is not contained in __str within this string. Found it? Returns the index. Not found? npos, and honestly, same. π
π«Ά lowkey referenced bystd::basic_string<_CharT>::find_last_not_of(),std::basic_string<_CharT>::find_last_not_of(), andstd::basic_string<_CharT, std::char_traits<_CharT>, std::allocator<_CharT>>::swap().
π find_last_not_of β string version, the remix
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_not_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const
[inline], [noexcept]
Find last position of a character not in string.
Parameters
__strβ string containing the characters to avoid.__posβ index of the character to search back from (default end).
Returns
Index of the last occurrence.
Same energy as above, fr fr: start at __pos, walk backward, find a character that is not in __str. Gotcha index? Returned. No dice? npos. Periodt.
π find_last_of β single character edition
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(_CharT __c, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character.
Parameters
__cβ the character you're locating.__posβ index of the character to search back from (default end).
Returns
Index of the last occurrence. β¨
Starting from __pos, it searches backward for __c within this string. Found it? Returns the index where it was found. Not found? npos. That's the whole vibe check.
π
Note: equivalent to rfind(__c, __pos).
π find_last_of β single character, the remix
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(_CharT __c, size_type __pos = npos) const
[inline], [noexcept]
Find last position of a character.
Parameters
__cβ character to locate.__posβ index of the character to search back from (default end).
Returns
Index of the last occurrence.
Starts at __pos, goes backward looking for __c. Found β index. Not found β npos. No cap. π§
π
Note: equivalent to rfind(__c, __pos).
π¦ find_last_of β C substring, first __n chars only
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos, size_type __n) const
[nodiscard], [constexpr], [noexcept]
Find last position of a character of C substring.
Parameters
__sβ C string containing the characters you wanna locate.__posβ index of the character to search back from.__nβ number of characters fromsto search for. π
Returns
Index of the last occurrence.
Starting from __pos, it searches backward for one of the first __n characters of __s within this string. Found one? Returns the index where it was found. Not found? npos, bestie.
π«Ά Referencesnpos, andstd::size().
πΈ find_last_of β C substring, unadorned version
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos, size_type __n) const
[noexcept]
Find last position of a character of C substring.
Parameters
__sβ C string containing characters to locate.__posβ index of the character to search back from.__nβ number of characters fromsto search for.
Returns
Index of the last occurrence.
Same deal: from __pos, search backward for one of the first __n characters of __s in this string. Found β index. Not found β npos. π
π find_last_of β C string, default pos
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character of C string.
Parameters
__sβ C string containing the characters to locate.__posβ index of the character to search back from (default end).
Returns
Index of the last occurrence.
Starting from __pos, it searches backward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos. Iconic behaviour tbh.
β find_last_of β C string, the remix
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const _CharT *__s, size_type __pos = npos) const
[inline], [noexcept]
Find last position of a character of C string.
Parameters
__sβ C string containing characters to locate.__posβ index of the character to search back from (default end).
Returns
Index of the last occurrence.
Same as above, no frills: search backward from __pos for one of the chars in __s. Found β index, not found β npos. π
π find_last_of β string version
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept]
Find last position of a character of string.
Parameters
__strβ string containing the characters to locate.__posβ index of the character to search back from (default end).
Returns
Index of the last occurrence.
Starting from __pos, it searches backward for one of the characters of __str within this string. Found β returns the index where it was found. Not found β npos. Simple as that. β¨
π«Ά Referenced bystd::basic_string<_CharT>::find_last_of(), andstd::basic_string<_CharT>::find_last_of().
π§ find_last_of β string version, the remix
template<typename _CharT, typename _Traits, typename _Alloc>
size_type std::basic_string<_CharT, _Traits, _Alloc>::find_last_of(const basic_string<_CharT, _Traits, _Alloc> &__str, size_type __pos = npos) const
[inline], [noexcept]
Find last position of a character of string.
Parameters
__strβ string containing characters to locate.__posβ index of the character to search back from (default end).
Returns
Index of the last occurrence.
Search backward from __pos for one of the characters of __str. Found β index. Not found β npos. That's it, that's the function. π
π front β the read/write version
template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string<_CharT, _Traits, _Alloc>::front()
[inline]
Returns a read/write reference to the data at the first element of the string. Yes bestie, you can literally write to it. Main character energy. π
π front β the const version, fully loaded
template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string<_CharT, _Traits, _Alloc>::front() const
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reference to the data at the first element of the string. Look but don't touch, babe. π
π front β the const version, the remix
template<typename _CharT, typename _Traits, typename _Alloc>
const_reference std::basic_string<_CharT, _Traits, _Alloc>::front() const
[inline], [noexcept]
Returns a read-only (constant) reference to the data at the first element of the string.
π₯ front β read/write, fully loaded
template<typename _CharT, typename _Traits, typename _Alloc>
reference std::basic_string<_CharT, _Traits, _Alloc>::front()
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read/write reference to the data at the first element of the string. Go off, edit that first char. π
π get_allocator β who made you
template<typename _CharT, typename _Traits, typename _Alloc>
allocator_type std::basic_string<_CharT, _Traits, _Alloc>::get_allocator() const
[inline], [nodiscard], [constexpr], [noexcept]
Return copy of allocator used to construct this string. It's giving "let me see your birth certificate" but make it wholesome. πΈ
π«Ά Referenced bystd::basic_string<_CharT>::~basic_string(),std::basic_string<_CharT>::assign(),std::basic_string<_CharT>::clear(),std::operator+(),std::operator+(),std::operator+(),std::operator+(),std::operator+(),reserve(),reserve(), andswap().
β¨ get_allocator β the remix
template<typename _CharT, typename _Traits, typename _Alloc>
allocator_type std::basic_string<_CharT, _Traits, _Alloc>::get_allocator() const
[inline], [noexcept]
Return copy of allocator used to construct this string. Same allocator lore, same copy, no notes. π
π
insert β drop one character in
template<typename _CharT, typename _Traits, typename _Alloc>
iterator std::basic_string<_CharT, _Traits, _Alloc>::insert(__const_iterator __p, _CharT __c)
[inline], [constexpr]
Insert one character.
Parameters
__pβ iterator referencing the position in the string to insert at.__cβ the character to insert.
Returns
Iterator referencing the newly inserted char. β¨
Exceptions
std::length_errorβ if the new length exceedsmax_size().
Inserts character __c at the position referenced by __p. If adding the character causes the length to exceed max_size(), length_error gets thrown. If __p is beyond the end of the string, out_of_range gets thrown. And listen β the value of the string doesn't change if an error is thrown. So no half-finished messes. π«Ά
π insert β drop a whole range in
template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
iterator std::basic_string<_CharT, _Traits, _Alloc>::insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
[inline], [constexpr]
Insert a range of characters.
Parameters
__pβ const_iterator referencing the location in the string to insert at.__begβ start of the range.__endβ end of the range.
Returns
Iterator referencing the first inserted char. π
Exceptions
std::length_errorβ if the new length exceedsmax_size().
Inserts the characters in the range [beg,end). If adding those characters causes the length to exceed max_size(), length_error gets thrown. And again, bestie: the value of the string doesn't change if an error is thrown. Nothing changes, no chaos, just vibes. π
okay so insert() is literally the friend who shows up to every party with a plus-one, a plus-two, and a whole plus-entourage π there are SO many overloads and they all do basically the same vibe: drop some characters in at a spot you pick. let's go one by one, no skipping, bestie π
template<typename _CharT, typename _Traits, typename _Alloc>
iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (const_iterator __p, initializer_list< _CharT > __l) [inline], [constexpr]
Insert an initializer_list of characters. basically a little bundle of chars walks in and sits down at __p π
Parameters
__pβ Iterator referencing location in string to insert at.__lβ The initializer_list of characters to insert.
Exceptions
std::length_errorβ If new length exceedsmax_size().
template<typename _CharT, typename _Traits, typename _Alloc>
iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (const_iterator __p, size_type __n, _CharT __c) [inline], [constexpr]
Insert multiple characters. same character, __n times, over and over, like a group chat spam π
Parameters
__pβ Const_iterator referencing location in string to insert at.__nβ Number of characters to insert__cβ The character to insert.
Returns
- Iterator referencing the first inserted char.
Exceptions
std::length_errorβ If new length 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. (yes bestie, it's giving transactional, we love a clean rollback β¨)
Referenced by std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), and std::basic_string< _CharT >::insert().
template<typename _CharT, typename _Traits, typename _Alloc>
iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, _CharT __c) [inline]
Insert one character. just the one. singular. main character energy π
Parameters
__pβ Iterator referencing position in string to insert at.__cβ The character to insert.
Returns
- Iterator referencing newly inserted char.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts character __c at position referenced by __p. If adding character causes the length to exceed max_size(), length_error is thrown. If __p is beyond end of string, out_of_range is thrown. The value of the string doesn't change if an error is thrown. π«Ά
template<typename _CharT, typename _Traits, typename _Alloc>
template<class _InputIterator>
void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, _InputIterator __beg, _InputIterator __end) [inline]
Insert a range of characters. a whole squad, [__beg, __end) style π
Parameters
__pβ Iterator referencing location in string to insert at.__begβ Start of range.__endβ End of range.
Exceptions
std::length_errorβ If new length 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.
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, initializer_list< _CharT > __l) [inline]
Insert an initializer_list of characters.
Parameters
__pβ Iterator referencing location in string to insert at.__lβ The initializer_list of characters to insert.
Exceptions
std::length_errorβ If new length exceedsmax_size().
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p, size_type __n, _CharT __c) [inline]
Insert multiple characters.
Parameters
__pβ Iterator referencing location in string to insert at.__nβ Number of characters to insert__cβ The character to insert.
Exceptions
std::length_errorβ If new length 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. π
and now we switch from iterators to indices, bestie β same energy, different address system π¦
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s) [inline], [constexpr]
Insert a C string.
Parameters
__posβ Position in string to insert at.__sβ The C string to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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. π₯
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s) [inline]
Insert a C string.
Parameters
__posβ Position in string to insert at.__sβ The C string to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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.
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s, size_type __n) [inline], [constexpr]
Insert a C substring. just the first __n chars of __s, like, the highlight reel β¨
Parameters
__posβ Position in string to insert at.__sβ The C string to insert.__nβ The number of characters to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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.
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, const _CharT * __s, size_type __n)
Insert a C substring.
Parameters
__posβ Position in string to insert at.__sβ The C string to insert.__nβ The number of characters to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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. π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, size_type __n, _CharT __c) [inline], [constexpr]
Insert multiple characters.
Parameters
__posβ Index in string to insert at.__nβ Number of characters to insert__cβ The character to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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. π (she's so careful with your data, we stan)
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos, size_type __n, _CharT __c) [inline]
Insert multiple characters.
Parameters
__posβ Index in string to insert at.__nβ Number of characters to insert__cβ The character to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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.
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1, const basic_string< _CharT, _Traits, _Alloc > & __str) [inline], [constexpr]
Insert value of a string. a whole other string walks in and takes a seat π«Ά
Parameters
__pos1β Position in string to insert at.__strβ The string to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts value of __str starting at __pos1. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1, const basic_string< _CharT, _Traits, _Alloc > & __str) [inline]
Insert value of a string.
Parameters
__pos1β Position in string to insert at.__strβ The string to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().
Inserts value of __str starting at __pos1. If adding characters causes the length to exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos1, const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos2, size_type __n = npos) [inline], [constexpr]
Insert a substring. not the whole string β just a slice of it, __pos2 to __pos2 + __n kinda situation πΈ
Parameters
__pos1β Position in string to insert at.__strβ The string to insert.__pos2β Start of characters in str to insert.__nβ Number of characters to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().std::out_of_rangeβ If pos1 > size() or__pos2> str.size().
heads up bestie: that__ndefaults tonpos, so if you don't pass it you get everything from__pos2to the end π and yeah,out_of_rangeis lurking if your positions are doing too much π
and that's the whole insert() cinematic universe... but we're not done, there's more coming ππ
okay so starting at pos1, you're sliding in __n characters of __str, beginning with __pos2. If adding those characters pushes the length over max_size(), a length_error gets thrown π. And if __pos1 is past the end of this string, or __pos2 is past the end of __str, out_of_range gets thrown. Bestie, listen: the value of the string does not change if an error gets thrown. Not one character. π«Ά
insert β the substring edition π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::insert (size_type __pos1, const basic_string<_CharT, _Traits, _Alloc> & __str, size_type __pos2, size_type __n = npos) [inline]
Insert a substring. π
Parameters
__pos1β position in the string where you're inserting.__strβ the string you're inserting.__pos2β where instrthe characters you're inserting start.__nβ how many characters to insert.
Returns
- A reference to this string. π
Exceptions
std::length_errorβ if the new length exceedsmax_size().std::out_of_rangeβ ifpos1 > size()or__pos2 > str.size().
Starting at pos1, insert __n characters of __str beginning with __pos2. If adding those characters makes the length exceed max_size(), length_error gets thrown. If __pos1 is beyond the end of this string, or __pos2 is beyond the end of __str, out_of_range gets thrown. And again, for the people in the back: the value of the string doesn't change if an error is thrown. π§
length π
template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::length () const [inline], [nodiscard], [constexpr], [noexcept]
Returns the number of characters in the string, not including any null-termination. That's the whole vibe, it's giving "how many actual letters, bestie". β¨
Referenced by std::basic_string<_CharT>::basic_string(), std::basic_string<_CharT>::basic_string(), std::__cxx11::collate<_CharT>::do_compare(), std::__cxx11::collate<_CharT>::do_transform(), std::basic_string<_CharT>::operator=(), std::regex_replace(), and reserve(). π¦
length (the other one) πΈ
template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::length () const [inline], [noexcept]
Returns the number of characters in the string, not including any null-termination. Same energy, slightly different qualifiers β both of them live here, no cap. π
max_size π
template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::max_size () const [inline], [nodiscard], [constexpr], [noexcept]
Returns the size() of the largest possible string. Like, the absolute ceiling. The main character's upper limit. π₯
Referenced by std::getline(), and std::operator>>(). π
max_size (the other one) π
template<typename _CharT, typename _Traits, typename _Alloc> size_type std::basic_string<_CharT, _Traits, _Alloc>::max_size () const [inline], [noexcept]
Returns the size() of the largest possible string. Yes, again. Two flavours, same answer. π
operator+= β character flavour β
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (_CharT __c) [inline], [constexpr]
Append a character. β¨
Parameters
__cβ the character to append.
Returns
- A reference to this string.
operator+= β character flavour, round two π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (_CharT __c) [inline]
Append a character.
Parameters
__cβ the character to append.
Returns
- A reference to this string.
operator+= β C string flavour π¦
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const _CharT * __s) [inline], [constexpr]
Append a C string.
Parameters
__sβ the C string to append.
Returns
- A reference to this string.
operator+= β C string flavour, round two πΈ
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const _CharT * __s) [inline]
Append a C string.
Parameters
__sβ the C string to append.
Returns
- A reference to this string.
operator+= β string flavour π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline], [constexpr]
Append a string to this string. Gluing two besties together fr fr. π«Ά
Parameters
__strβ the string to append.
Returns
- A reference to this string.
operator+= β string flavour, round two π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline]
Append a string to this string.
Parameters
__strβ the string to append.
Returns
- A reference to this string.
operator+= β initializer_list flavour β¨
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (initializer_list<_CharT> __l) [inline], [constexpr]
Append an initializer_list of characters. So very cute, so very convenient. π
Parameters
__lβ theinitializer_listof characters to be appended.
Returns
- A reference to this string.
operator+= β initializer_list flavour, round two π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator+= (initializer_list<_CharT> __l) [inline]
Append an initializer_list of characters.
Parameters
__lβ theinitializer_listof characters to be appended.
Returns
- A reference to this string.
operator= β character flavour π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (_CharT __c) [inline], [constexpr]
Set value to string of length 1. Glow-down to a single character, honestly iconic. π
Parameters
__cβ source character.
Assigning to a character makes this string length 1 and (*this)[0] == c. Periodt.
operator= β character flavour, round two π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (_CharT __c) [inline]
Set value to string of length 1.
Parameters
__cβ source character.
Assigning to a character makes this string length 1 and (*this)[0] == c.
operator= β move-assign flavour π₯
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (basic_string<_CharT, _Traits, _Alloc> && __str) [inline], [noexcept]
Move assign the value of str to this string. No copying, just vibes. π«
Parameters
__strβ source string.
The contents of str are moved into this string (without copying). str is a valid, but unspecified string. Like, it's still alive, but don't ask it what it is anymore. π
operator= β move-assign flavour, round two π¦
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (basic_string<_CharT, _Traits, _Alloc> && __str) [inline], [constexpr], [noexcept]
Move assign the value of str to this string.
Parameters
__strβ source string.
The contents of str are moved into this string (without copying). str is a valid, but unspecified string.
operator= β C string flavour πΈ
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const _CharT * __s) [inline], [constexpr]
Copy contents of s into this string.
Parameters
__sβ source null-terminated string.
operator= β C string flavour, round two π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const _CharT * __s) [inline]
Copy contents of s into this string.
Parameters
__sβ source null-terminated string.
operator= β copy-assign flavour π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline], [constexpr]
Assign the value of str to this string.
Parameters
__strβ source string.
operator= β copy-assign flavour, round two β¨
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (const basic_string<_CharT, _Traits, _Alloc> & __str) [inline]
Assign the value of str to this string.
Parameters
__strβ source string.
operator= β initializer_list flavour π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (initializer_list<_CharT> __l) [inline], [constexpr]
Set value to string constructed from initializer list.
Parameters
__lβstd::initializer_list.
operator= β initializer_list flavour, round two π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string & std::basic_string<_CharT, _Traits, _Alloc>::operator= (initializer_list<_CharT> __l) [inline]
Set value to string constructed from initializer list.
Parameters
__lβstd::initializer_list.
operator[] β read/write flavour π
template<typename _CharT, typename _Traits, typename _Alloc> reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) [inline], [nodiscard], [constexpr]
Subscript access to the data contained in the string. Array-style, super easy, we love her. π
Parameters
__posβ the index of the character to access.
Returns
- Read/write reference to the character.
This operator allows for easy, array-style, data access. But heads up: data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) π
operator[] β read/write flavour, round two π₯
template<typename _CharT, typename _Traits, typename _Alloc> reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) [inline]
Subscript access to the data contained in the string.
Parameters
__posβ the index of the character to access.
Returns
- Read/write reference to the character.
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) Also, this one unshares the string. π
operator[] β read-only flavour π¦
template<typename _CharT, typename _Traits, typename _Alloc> const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) const [inline], [nodiscard], [constexpr], [noexcept]
Subscript access to the data contained in the string.
Parameters
__posβ the index of the character to access.
Returns
- Read-only (constant) reference to the character.
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) πΈ
Referenced by std::basic_string<_CharT>::back(), std::basic_string<_CharT>::back(), std::basic_string<_CharT>::back(), std::basic_string<_CharT>::front(), std::basic_string<_CharT>::front(), and std::basic_string<_CharT>::front(). (Yes, each of them three times. The girls are obsessed. π)
operator[] β read-only flavour, round two π
template<typename _CharT, typename _Traits, typename _Alloc> const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[] (size_type __pos) const [inline], [noexcept]
Subscript access to the data contained in the string.
Parameters
__posβ the index of the character to access.
Returns
- Read-only (constant) reference to the character.
This operator allows for easy, array-style, data access. Note that data access with this operator is unchecked and out_of_range lookups are not defined. (For checked lookups see at().) β¨
π¦ pop_back() β the "bye bestie" button π¦
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::pop_back () [inline]
Removes the last character. That's it, that's the whole job. But listen β the string must be non-empty. Do NOT call this on an empty string, bestie, I am begging you. π
πΈ pop_back() (the constexpr/noexcept remix) πΈ
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::pop_back () [inline],
[constexpr], [noexcept]
Same energy, more sparkle: removes the last character. And again, the string must be non-empty. No cap on that. β¨
π push_back(_CharT __c) β add ONE lil guy π
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::push_back (_CharT __c)
[inline], [constexpr]
Appends a single character. Just one. One (1) character. π
Parameters
__cβ the character to append. your lil guy. your new bestie at the end of the string.
Referenced by std::__cxx11::collate< _CharT >::do_transform(), std::basic_string< _CharT >::operator+=(), std::tr2::operator>>(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(). Look at her, getting invited everywhere. π
π§ push_back(_CharT __c) (the plainer cut) π§
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::push_back (_CharT __c)
[inline]
Append a single character. Yep. Same deal.
Parameters
__cβ Character to append. π
π rbegin() β reverse iterator, going backwards like a queen π
template<typename _CharT, typename _Traits, typename _Alloc>
reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rbegin ()
[inline]
Returns a read/write reverse iterator that points to the last character in the string. Iteration is done in reverse element order (so, backwards, which is honestly a vibe).
Heads up: this one unshares the string. Just so you know. π
β¨ rbegin() const β read-only reverse, don't touch β¨
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::rbegin () const [inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reverse iterator pointing at the last character in the string. Iteration is done in reverse element order. Look with your eyes only, bestie. π
π rbegin() const (the shorter flavor) π
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::rbegin () const [inline], [noexcept]
Returns a read-only (constant) reverse iterator that points to the last character in the string. Iteration is done in reverse element order. Same facts, fewer tags. π«Ά
π₯ rbegin() (read/write, fully accessorized) π₯
template<typename _CharT, typename _Traits, typename _Alloc>
reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rbegin ()
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read/write reverse iterator that points to the last character in the string. Iteration is done in reverse element order. She's got all the attributes on. Iconic. π
π rend() β the reverse "one before the start" π
template<typename _CharT, typename _Traits, typename _Alloc>
reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rend ()
[inline]
Returns a read/write reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order.
Yup, this one unshares the string too. It's giving β¨commitmentβ¨.
β rend() const β read-only reverse end β
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::rend () const [inline], [nodiscard], [constexpr], [noexcept]
Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order. π¦
πΈ rend() const (compact edition) πΈ
template<typename _CharT, typename _Traits, typename _Alloc>
const_reverse_iterator std::basic_string< _CharT, _Traits, _Alloc
>::rend () const [inline], [noexcept]
Returns a read-only (constant) reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order. π
π
rend() (read/write, deluxe) π
template<typename _CharT, typename _Traits, typename _Alloc>
reverse_iterator std::basic_string< _CharT, _Traits, _Alloc >::rend ()
[inline], [nodiscard], [constexpr], [noexcept]
Returns a read/write reverse iterator that points to one before the first character in the string. Iteration is done in reverse element order. Periodt. π
π replace(__i1, __i2, const _CharT * __s) β swap a range for a C string π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, const _CharT * __s) [inline], [constexpr]
Replace range of characters with C string. Glow-up time. β¨
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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. (no half-done makeovers here, she's safe π)
π§ replace(__i1, __i2, const _CharT * __s, size_type __n) β C substring edition π§
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, const _CharT * __s, size_type __n)
[inline], [constexpr]
Replace range of characters with C substring.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.__nβ Number of characters fromsto 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(__i1, __i2, const basic_string & __str) β swap in a whole string π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, const basic_string< _CharT, _Traits, _Alloc
> & __str) [inline], [constexpr]
Replace range of characters with string.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__strβ String value to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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(__i1, __i2, size_type __n, _CharT __c) β many copies of one char π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (__const_iterator
__i1, __const_iterator __i2, size_type __n, _CharT __c) [inline],
[constexpr]
Replace range of characters with multiple characters.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__nβ Number of characters to insert.__cβ Character to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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(__i1, __i2, __k1, __k2) β range for range, iterator edition π₯
template<typename _CharT, typename _Traits, typename _Alloc> template<class
_InputIterator, typename = std::_RequireInputIter<_InputIterator>>
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace
(const_iterator __i1, const_iterator __i2, _InputIterator __k1,
_InputIterator __k2) [inline], [constexpr]
Replace range of characters with range. Trading one range for another, very fair, very balanced. π
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__k1β Iterator referencing start of range to insert.__k2β Iterator referencing end of range to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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(__i1, __i2, initializer_list< _CharT > __l) β brace-list glow-up π
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (const_iterator
__i1, const_iterator __i2, initializer_list< _CharT > __l) [inline],
[constexpr]
Replace range of characters with initializer_list. So { 'a', 'b', 'c' } coded, basically. β¨
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__lβ 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(__i1, __i2, __k1, __k2) β non-const iterator range version π
template<typename _CharT, typename _Traits, typename _Alloc> template<class
_InputIterator> basic_string & std::basic_string< _CharT, _Traits,
_Alloc >::replace (iterator __i1, iterator __i2, _InputIterator __k1,
_InputIterator __k2) [inline]
Replace range of characters with range. (Yeah, she's got a sibling. Family business. π )
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__k1β Iterator referencing start of range to insert.__k2β Iterator referencing end of range to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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(iterator __i1, iterator __i2, const _CharT * __s) β non-const C string swap β
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const _CharT * __s) [inline]
Replace range of characters with C string.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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(iterator __i1, iterator __i2, const _CharT * __s, size_type __n) β non-const C substring swap π¦
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const _CharT * __s, size_type __n) [inline]
Replace range of characters with C substring.
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__sβ C string value to insert.__nβ Number of characters fromsto insert.
Returns
- Reference to this string. π
Exceptions
std::length_errorβ thrown if the new length exceedsmax_size().
So basically: it deletes the characters in the range [__i1,__i2), and in their place it drops in the first __n characters of __s. β¨ If the resulting length goes over max_size(), length_error gets thrown β and if an error is thrown, the string itself does not change. Bestie, it's giving transactional. π
π replace (range β string)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline]
Replace range of characters with string. πΈ
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__strβ String value to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length exceedsmax_size().
It removes the characters in the range [__i1,__i2) and, right there in place, inserts the value of __str. If the length of the result exceeds max_size(), length_error is thrown. And again β the value of the string doesn't change if an error is thrown. π«Ά
π¦ replace (range β initializer_list)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, initializer_list< _CharT > __l) [inline]
Replace range of characters with initializer_list. π
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__lβ 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 (range β multiple chars)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1,
iterator __i2, size_type __n, _CharT __c) [inline]
Replace range of characters with multiple characters. β¨
Parameters
__i1β Iterator referencing start of range to replace.__i2β Iterator referencing end of range to replace.__nβ Number of characters to insert.__cβ Character to insert.
Returns
- Reference to this string.
Exceptions
std::length_errorβ If new length 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 (pos β string, constexpr edition)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline], [constexpr]
Replace characters with value from another string. π
Parameters
__posβ Index of first character to replace.__nβ Number of characters to be replaced.__strβ String to insert.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ If pos is beyond the end of this string.std::length_errorβ If new length 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 std::basic_string< _CharT >::append(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), and std::basic_string< _CharT >::replace(). π that is a LOT of references, it's booked and busy fr fr.
π
replace (pos β string, plain inline)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
[inline]
Replace characters with value from another string. π
Parameters
__posβ Index of first character to replace.__nβ Number of characters to be replaced.__strβ String to insert.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ If pos is beyond the end of this string.std::length_errorβ If new length 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. β¨
π replace (pos β C string, constexpr edition)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, const _CharT * __s) [inline], [constexpr]
Replace characters with value of a C string. π
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__sβ C string to insert.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ Ifpos > 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 (pos β C string, plain inline)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, const _CharT * __s) [inline]
Replace characters with value of a C string. πΈ
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__sβ C string to insert.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ Ifpos > 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 (pos β C substring, constexpr edition)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string<
_CharT, _Traits, _Alloc > & std::basic_string< _CharT, _Traits, _Alloc
>::replace (size_type __pos, size_type __n1, const _CharT * __s,
size_type __n2) [inline], [constexpr]
Replace characters with value of a C substring. π
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__sβ C string to insert.__n2β Number of characters from s to use.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ Ifpos1 > 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 (pos β C substring, plain)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, const _CharT * __s, size_type __n2)
Replace characters with value of a C substring. π
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__sβ C string to insert.__n2β Number of characters from s to use.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ Ifpos1 > 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 (pos β multiple chars, constexpr edition)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, size_type __n2, _CharT __c) [inline], [constexpr]
Replace characters with multiple characters. π
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__n2β Number of characters to insert.__cβ Character to insert.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ If__pos > size().std::length_errorβ If new length 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 (pos β multiple chars, plain inline)
template<typename _CharT, typename _Traits, typename _Alloc> basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos,
size_type __n1, size_type __n2, _CharT __c) [inline]
Replace characters with multiple characters. π
Parameters
__posβ Index of first character to replace.__n1β Number of characters to be replaced.__n2β Number of characters to insert.__cβ Character to insert.
Returns
- Reference to this string.
Exceptions
std::out_of_rangeβ If__pos > size().std::length_errorβ If new length 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 β the string-flavored one, constexpr cut π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos1,
size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos2, size_type __n2 = npos) [inline], [constexpr]
Replace characters with value from another string. bestie it literally swaps a chunk of your string for a chunk of someone else's string, no cap β¨
Parameters
__pos1β Index of first character to replace.__n1β Number of characters to be replaced.__strβ String to insert.__pos2β Index of first character of str to use.__n2β Number of characters from str to use.
Returns
Reference to this string. π«Ά
Exceptions
std::out_of_rangeβ If__pos1 > size()or__pos2 > __str.size().std::length_errorβ If new length 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.
not it throwing an error and mutating your string halfway through β good news: it doesn't do that, the value stays put if anything goes wrong π
replace β same function, but the non-constexpr twin π¦
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos1,
size_type __n1, const basic_string< _CharT, _Traits, _Alloc > & __str,
size_type __pos2, size_type __n2 = npos) [inline]
Replace characters with value from another string. yep it's the same vibe as above, just without [constexpr] on the attribute list, we love a matching set π
Parameters
__pos1β Index of first character to replace.__n1β Number of characters to be replaced.__strβ String to insert.__pos2β Index of first character of str to use.__n2β Number of characters from str to use.
Returns
Reference to this string.
Exceptions
std::out_of_rangeβ If__pos1 > size()or__pos2 > __str.size().std::length_errorβ If new length 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 β no args, constexpr edition π§
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve () [constexpr]
Equivalent to shrink_to_fit(). that's it, that's the whole function, it's giving one-line legend β
References capacity(), get_allocator(), and length().
Referenced by std::basic_string< _CharT >::push_back(), and std::basic_string< _CharT >::shrink_to_fit().
reserve β no args, the plain one π
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve ()
Equivalent to shrink_to_fit(). same energy, missing the [constexpr] tag, iconic either way π
reserve β with a size argument, constexpr edition π₯
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve (size_type __res_arg)
[constexpr]
Attempt to preallocate enough memory for specified number of characters. okay so this is the "bestie book my table in advance so we don't get seated in the overflow room" function π«Ά
Parameters
__res_argβ Number of characters required.
Exceptions
std::length_errorβ If__res_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. no more surprise realloc mid-loop, we love to see it β¨
References capacity(), get_allocator(), and std::size().
Referenced by std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::tr2::operator>>(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow().
reserve β with a size argument, the plain one πΈ
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::reserve (size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
Parameters
__res_argβ Number of characters required.
Exceptions
std::length_errorβ If__res_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.
resize β just the size, inline + constexpr π
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n)
[inline], [constexpr]
Resizes the string to the specified number of characters. glow up or glow down, your call π
Parameters
__nβ Number of characters the string should contain.
This function will resize the string to the specified length. If the new size is smaller than the string's current size the string is truncated, otherwise the string is extended and new characters are default-constructed. For basic types such as char, this means setting them to 0. yes girl the new spots come pre-filled with zeros, not mystery garbage π
resize β just the size, inline only β
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n)
[inline]
Resizes the string to the specified number of characters.
Parameters
__nβ Number of characters the string should contain.
This function will resize the string to the specified length. If the new size is smaller than the string's current size the string is truncated, otherwise the string is extended and new characters are default-constructed. For basic types such as char, this means setting them to 0.
resize β size plus a fill char, constexpr edition π
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n,
_CharT __c) [constexpr]
Resizes the string to the specified number of characters. now with a custom filler character, we're customizing β¨
Parameters
__nβ Number of characters the string should contain.__cβ Character to fill any new elements.
This function will resize the string to the specified number of characters. If the number is smaller than the string's current size the string is truncated, otherwise the string is extended and new elements are set to __c.
References append(), erase(), and size().
Referenced by std::basic_string< _CharT >::resize().
resize β size plus a fill char, the plain one π
template<typename _CharT, typename _Traits, typename _Alloc>
void
std::basic_string< _CharT, _Traits, _Alloc >::resize (size_type __n,
_CharT __c)
Resizes the string to the specified number of characters.
Parameters
__nβ Number of characters the string should contain.__cβ Character to fill any new elements.
This function will resize the string to the specified number of characters. If the number is smaller than the string's current size the string is truncated, otherwise the string is extended and new elements are set to __c.
rfind β a single character, constexpr + noexcept cut π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc >::size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (_CharT __c,
size_type __pos = npos) const [nodiscard], [constexpr], [noexcept]
Find last position of a character. the backwards-search bestie, she goes from the end and walks it back π¦
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos. npos means "not found bestie, she's not here" π
References npos, and std::size().
rfind β a single character, noexcept only π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (_CharT __c,
size_type __pos = npos) const [noexcept]
Find last position of a character.
Parameters
__cβ Character to locate.__posβ Index of character to search back from (default end).
Returns
Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
rfind β a C substring, constexpr + noexcept cut π
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string< _CharT, _Traits, _Alloc >::size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos, size_type __n) const [nodiscard], [constexpr], [noexcept]
Find last position of a C substring. only the first __n characters of __s get to come to the party π
Parameters
__sβ C string to locate.__posβ Index of character to search back from.__nβ Number of characters from s to search for.
Returns
Index of start of last occurrence.
Starting from __pos, searches backward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos.
References std::min(), npos, and std::size().
rfind β a C substring, noexcept only π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos, size_type __n) const [noexcept]
Find last position of a C substring.
Parameters
__sβ C string to locate.__posβ Index of character to search back from.__nβ Number of characters from s to search for.
Returns
Index of start of last occurrence.
Starting from __pos, searches backward for the first __n characters in __s within this string. If found, returns the index where it begins. If not found, returns npos.
rfind β a whole C string, inline + constexpr cut π
template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos = npos) const [inline], [nodiscard], [constexpr]
Find last position of a C string. the whole null-terminated situation, backwards, she ate π₯
Parameters
__sβ C string to locate.__posβ Index of character to start search at (default end).
Returns
Index of start of last occurrence.
Starting from __pos, searches backward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos.
rfind β a whole C string, inline + noexcept cut πΈ
template<typename _CharT, typename _Traits, typename _Alloc>
size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _CharT * __s,
size_type __pos = npos) const [inline], [noexcept]
Find last position of a C string.
Parameters
__sβ C string to locate.__posβ Index of character to start search at (default end).
Returns
Index of start of last occurrence.
Starting from __pos, searches backward for the value of __s within this string. If found, returns the index where it begins. If not found, returns npos.
that's the rfind family complete bestie, all four flavors plus their twins, we're so back π«Ά
π¦ rfind() β first one, the fancy one
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const basic_string<
_CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const
[inline], [nodiscard], [constexpr], [noexcept]
Find last position of a string. π like, it goes backwards bestie, and it is NOT playing.
Parameters
__strβ String to locate.__posβ Index of character to search back from (default end).
Returns
Index of start of last occurrence.
Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos. π (yes the sad one)
Referenced by std::basic_string< _CharT >::find_last_of(), std::basic_string< _CharT >::rfind(), std::basic_string< _CharT >::rfind(), std::basic_string< _CharT >::rfind(), and std::basic_string< _CharT >::rfind().
π¦ rfind() β second one, the chill version
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::rfind (const basic_string<
_CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const
[inline], [noexcept]
Find last position of a string. π same energy, different attribute list, no cap.
Parameters
__strβ String to locate.__posβ Index of character to search back from (default end).
Returns
Index of start of last occurrence.
Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos. π
πΈ shrink_to_fit() β first one
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::shrink_to_fit () [inline],
[constexpr], [noexcept]
A non-binding request to reduce capacity() to size(). β¨ key word is non-binding, bestie β it's a request, not a command. The library can simply say "no" and you just have to live with that. π«Ά
πΈ shrink_to_fit() β second one
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::shrink_to_fit () [inline],
[noexcept]
A non-binding request to reduce capacity() to size(). π¦ same little request, same non-binding energy.
π size() β the big one
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::size () const [inline],
[nodiscard], [constexpr], [noexcept]
Returns the number of characters in the string, not including any null-termination. π like yes, the null terminator is there vibing in the background but she is not invited to the count. periodt.
Referenced by std::tr2::dynamic_bitset< _WordT, _Alloc >::dynamic_bitset(), std::basic_string< _CharT >::append(), std::basic_string< _CharT >::append(), std::basic_regex< char >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::assign(), std::basic_string< _CharT >::at(), std::basic_string< _CharT >::at(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::back(), std::basic_string< _CharT >::cend(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::empty(), std::basic_string< _CharT >::end(), std::basic_string< _CharT >::end(), std::basic_string< _CharT >::end(), std::basic_string< _CharT >::find(), std::basic_string< _CharT >::find_first_not_of(), std::basic_string< _CharT >::find_first_of(), std::basic_string< _CharT >::find_last_of(), std::match_results< _BidirectionalIterator, polymorphic_allocator< sub_match< _BidirectionalIterator > > >< const char * >::format(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::from_bytes(), std::basic_string< _CharT >::insert(), std::basic_string< _CharT >::length(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::operator+(), std::basic_string< _CharT >::operator=(), std::operator==(), std::tr2::operator>>(), std::basic_string< _CharT >::operator[](), std::basic_string< _CharT >::operator[](), std::basic_string< _CharT >::pop_back(), std::basic_string< _CharT >::pop_back(), std::basic_string< _CharT >::push_back(), std::basic_string< _CharT >::replace(), std::basic_string< _CharT >::replace(), resize(), std::basic_stringbuf< char >::str(), std::wstring_convert< _Codecvt, _Elem, _Wide_alloc, _Byte_alloc >::to_bytes(), std::regex_traits< _CharT >::transform(), and std::regex_traits< _CharT >::transform_primary().
It's giving "literally everyone depends on me" main character energy, and honestly? deserved. π
π size() β the chill version
template<typename _CharT, typename _Traits, typename _Alloc> size_type
std::basic_string< _CharT, _Traits, _Alloc >::size () const [inline],
[noexcept]
Returns the number of characters in the string, not including any null-termination. π same answer, no [nodiscard]/[constexpr] tags, still iconic.
π§ substr()
template<typename _CharT, typename _Traits, typename _Alloc> basic_string
std::basic_string< _CharT, _Traits, _Alloc >::substr (size_type __pos =
0, size_type __n = npos) const [inline], [nodiscard], [constexpr]
Get a substring. π the glow-up snippet, a whole new string made out of a chunk of your old one.
Parameters
__posβ Index of first character (default 0).__nβ Number of characters in substring (default remainder).
Returns
The new string.
Exceptions
std::out_of_rangeβ If__pos > size().
Construct and return a new string using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown. π so watch your indices bestie, the library will yell.
π§ substr() β the chill version
template<typename _CharT, typename _Traits, typename _Alloc> basic_string
std::basic_string< _CharT, _Traits, _Alloc >::substr (size_type __pos =
0, size_type __n = npos) const [inline]
Get a substring. π¦
Parameters
__posβ Index of first character (default 0).__nβ Number of characters in substring (default remainder).
Returns
The new string.
Exceptions
std::out_of_rangeβ If__pos > size().
Construct and return a new string using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown.
π¦ subview()
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string_view< _CharT, _Traits > std::basic_string< _CharT, _Traits,
_Alloc >::subview (size_type __pos = 0, size_type __n = npos) const
[inline], [nodiscard], [constexpr]
Get a subview. β¨ not a copy, a view β like looking at your string through a cute little window instead of screenshotting the whole thing. π«Ά
Parameters
__posβ Index of first character (default 0).__nβ Number of characters in subview (default remainder).
Returns
The subview.
Exceptions
std::out_of_rangeβ If__pos > size().
Construct and return a subview using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown. π
π¦ subview() β the second listing, same vibe
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string_view< _CharT, _Traits > std::basic_string< _CharT, _Traits,
_Alloc >::subview (size_type __pos = 0, size_type __n = npos) const
[inline], [nodiscard], [constexpr]
Get a subview. π
Parameters
__posβ Index of first character (default 0).__nβ Number of characters in subview (default remainder).
Returns
The subview.
Exceptions
std::out_of_rangeβ If__pos > size().
Construct and return a subview using the __n characters starting at __pos. If the string is too short, use the remainder of the characters. If __pos is beyond the end of the string, out_of_range is thrown.
π₯ swap()
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::swap (basic_string<
_CharT, _Traits, _Alloc > & __s) [constexpr], [noexcept]
Swap contents with another string. π the trading-places moment, and it's giving constant time, so it's basically instant, no cap.
Parameters
__sβ String to swap with.
Exchanges the contents of this string with that of __s in constant time. β‘
References
basic_string(), and get_allocator().
Referenced by
std::basic_string< _CharT >::assign(), and std::basic_string< _CharT >::operator=().
π₯ swap() β the chill version
template<typename _CharT, typename _Traits, typename _Alloc> void
std::basic_string< _CharT, _Traits, _Alloc >::swap (basic_string<
_CharT, _Traits, _Alloc > & __s) [noexcept]
Swap contents with another string. π¦
Parameters
__sβ String to swap with.
Exchanges the contents of this string with that of __s in constant time.
πΎ Member Data Documentation πΎ
π npos
template<typename _CharT, typename _Traits, typename _Alloc> const size_type
std::basic_string< _CharT, _Traits, _Alloc >::npos [static]
Value returned by various member functions when they fail. π the official "it's not here bestie" value β static, constant, and forever the bearer of bad news.
Referenced by std::bitset< _Nb >::bitset(), std::tr2::dynamic_bitset< _WordT, _Alloc >::dynamic_bitset(), find(), find(), find_first_not_of(), find_first_not_of(), find_first_of(), find_last_not_of(), find_last_not_of(), find_last_of(), rfind(), and rfind().
βοΈ Author βοΈ
Generated automatically by Doxygen for libstdc++ from the source code. π€ not me getting written by a doc generator and still having the most lore in the whole library π
and that's the whole page bestie!! πβ¨ libstdc++ made this one, and this gorgeous thing lives at std::basic..., _Alloc >(3) β you just read the entire std::basic_string manual, all 19 parts, and honestly? ate. no crumbs. go take a nap, you earned it π«Άπ
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms