STD::BASIC_STRING(3cxx)
๐ std::basic_string< _CharT, _Traits, _Alloc > ๐
okay so this is the (3cxx) manual page bestie, and it's a big one โ sit down, hydrate, we're doing this ๐ซถ
โจ NAME โจ
std::basic_string< _CharT, _Traits, _Alloc > โ managing sequences of characters and character-like objects. that's the whole job. that's the assignment. iconic behaviour, no notes. ๐
๐ธ SYNOPSIS ๐ธ
#include <string>
Inherited by __gnu_debug::basic_string< _CharT, _Traits, _Allocator >. just so u know who else is in the group chat ๐
๐ Public Types ๐
bestie, this is the type-alias lineup. every single one, exactly as written, no cap:
typedef _Alloc allocator_typeโ the allocator, as itself ๐typedef __gnu_cxx::__normal_iterator< const_pointer, basic_string > const_iteratorโ the const iterator, wrapped in the__gnu_cxxnormal_iterator situationtypedef _CharT_alloc_traits::const_pointer const_pointerโ const pointer, straight from_CharT_alloc_traitstypedef const value_type & const_referenceโ a const reference to avalue_typetypedef std::reverse_iterator< const_iterator > const_reverse_iteratorโ reverse iterator but make it const, walk backwards bestie ๐ถโโ๏ธtypedef _CharT_alloc_traits::difference_type difference_typeโ difference type, courtesy of_CharT_alloc_traitstypedef __gnu_cxx::__normal_iterator< pointer, basic_string > iteratorโ the regular iterator, same normal_iterator vibetypedef _CharT_alloc_traits::pointer pointerโ pointer, also from_CharT_alloc_traitstypedef value_type & referenceโ a plain reference to avalue_typetypedef std::reverse_iterator< iterator > reverse_iteratorโ reverse iterator, un-const editiontypedef _CharT_alloc_traits::size_type size_typeโ size type, again from_CharT_alloc_traits(she's everywhere and she's thriving) ๐typedef _Traits traits_typeโ the traits, astraits_typetypedef _Traits::char_type value_typeโ and the actual character type lives at_Traits::char_type, which isvalue_type. yes, it's giving family tree ๐ณ
that's just the synopsis bestie, the rest is coming ๐๐
๐ Public Member Functions ๐
okay bestie, buckle up ๐
this is the whole member-function lineup โ the entire friend group of basic_string. Every constructor, every find, every little noexcept she's wearing. No skipping, no summarizing, we're going through all of them fr fr. ๐ซถ
basic_string () noexceptโ the default constructor, makes you a cute empty string. minimal, iconic, does exactly what it says.template<class _InputIterator > basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc())โ builds the string as a copy of a range โจbasic_string (basic_string &&__str) noexceptโ the move constructor, she moves the string instead of copying. main character energy, no cap ๐ฅbasic_string (basic_string &&__str, const _Alloc &__a)โ no blurb in the original for this one, she's just living her truth ๐basic_string (const _Alloc &__a)โ constructs an empty string using allocator a. lowkey cozy.template<typename = _RequireAllocator<_Alloc>> basic_string (const _CharT *__s, const _Alloc &__a=_Alloc())โ constructs the string as a copy of a C string ๐basic_string (const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())โ constructs the string initialized by a character arraytemplate<typename _Tp , typename = _If_sv<_Tp, void>> basic_string (const _Tp &__t, const _Alloc &__a=_Alloc())โ constructs the string from astring_view๐ฆtemplate<typename _Tp , typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>> basic_string (const _Tp &__t, size_type __pos, size_type __n, const _Alloc &__a=_Alloc())โ constructs the string from a substring of astring_viewbasic_string (const basic_string &__str)โ copy constructor, constructs the string with a copy of the value of str. the classic ๐basic_string (const basic_string &__str, const _Alloc &__a)โ again, no blurb in the original, she's just vibing ๐ธbasic_string (const basic_string &__str, size_type __pos, const _Alloc &__a=_Alloc())โ constructs the string as a copy of a substringbasic_string (const basic_string &__str, size_type __pos, size_type __n)โ constructs the string as a copy of a substring (yes, again, she has range)basic_string (const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a)โ constructs the string as a copy of a substring, this time with an allocator toobasic_string (initializer_list< _CharT > __l, const _Alloc &__a=_Alloc())โ constructs the string from an initializer list โจbasic_string (size_type __n, _CharT __c, const _Alloc &__a=_Alloc())โ constructs the string as n copies of the character, multiple characters slay~basic_string () noexceptโ the destructor, destroys the string instance. bye bestie, it's giving closure ๐template<typename _Operation > void __resize_and_overwrite (size_type __n, _Operation __op)โ non-standard version ofresize_and_overwritefor C++11 and above. yes she's extra, that's the point ๐template<typename _InputIterator > basic_string< _CharT, _Traits, _Alloc > & _M_replace_dispatch (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2, __false_type)โ internal helper, no blurb in the original, we respect her privacy ๐template<typename _InIterator > _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, forward_iterator_tag)โ another internal helper, also no blurb, also iconic
๐ the append era ๐
template<class _InputIterator > basic_string & append (_InputIterator __first, _InputIterator __last)โ append a range of charactersbasic_string & append (const _CharT *__s)โ append a C stringbasic_string & append (const _CharT *__s, size_type __n)โ append a C substringtemplate<typename _Tp > _If_sv< _Tp, basic_string & > append (const _Tp &__svt)โ append astring_view๐ฆtemplate<typename _Tp > _If_sv< _Tp, basic_string & > append (const _Tp &__svt, size_type __pos, size_type __n=npos)โ append a range of characters from astring_viewbasic_string & append (const basic_string &__str)โ append a string to this string ๐basic_string & append (const basic_string &__str, size_type __pos, size_type __n=npos)โ append a substringbasic_string & append (initializer_list< _CharT > __l)โ append aninitializer_listof characters โจbasic_string & append (size_type __n, _CharT __c)โ append multiple characters. she stacking them ๐
๐ฆ the assign era ๐ฆ
template<class _InputIterator > basic_string & assign (_InputIterator __first, _InputIterator __last)โ set the value to a range of charactersbasic_string & assign (basic_string &&__str) noexcept(allocator_traits< _Alloc >::is_always_equal::value)โ set the value to the contents of another string, and check out thatnoexceptclause ๐basic_string & assign (const _CharT *__s)โ set the value to the contents of a C stringbasic_string & assign (const _CharT *__s, size_type __n)โ set the value to a C substringtemplate<typename _Tp > _If_sv< _Tp, basic_string & > assign (const _Tp &__svt)โ set the value from astring_viewtemplate<typename _Tp > _If_sv< _Tp, basic_string & > assign (const _Tp &__svt, size_type __pos, size_type __n=npos)โ set the value from a range of characters in astring_viewbasic_string & assign (const basic_string &__str)โ set the value to the contents of another string ๐ซถbasic_string & assign (const basic_string &__str, size_type __pos, size_type __n=npos)โ set the value to a substring of a stringbasic_string & assign (initializer_list< _CharT > __l)โ set the value to aninitializer_listof charactersbasic_string & assign (size_type __n, _CharT __c)โ set the value to multiple characters ๐
๐ access + the basics ๐
reference at (size_type __n)โ provides access to the data contained in the string (and yes, she will check your bounds, behave)const_reference at (size_type __n) constโ provides access to the data contained in the string, const editionreference back ()โ no blurb in the original, just the back element doing her thingconst_reference back () const noexceptโ same, but const andnoexceptiterator begin ()โ the beginning iterator, no blurb needed, she's self-explanatoryconst_iterator begin () const noexceptโ const begin,noexcept, slaying quietlyconst _CharT * c_str () const noexceptโ return a const pointer to the null-terminated contents ๐size_type capacity () const noexceptโ no blurb in the original, she's just here holding the capacityconst_iterator cbegin () const noexceptโ const begin again but with a c, iykykconst_iterator cend () const noexceptโ the matching c-endvoid clear () noexceptโ no blurb in the original, but the name says it all bestie ๐int compare (const _CharT *__s) const noexceptโ compare to a C stringtemplate<typename _Tp > _If_sv< _Tp, int > compare (const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)โ compare to astring_viewint compare (const basic_string &__str) constโ compare to a string ๐ธtemplate<typename _Tp > _If_sv< _Tp, int > compare (size_type __pos, size_type __n, const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value)โ compare to astring_viewint compare (size_type __pos, size_type __n, const basic_string &__str) constโ compare a substring to a stringint compare (size_type __pos, size_type __n1, const _CharT *__s) constโ compare a substring to a C stringint compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) constโ compare a substring against a character arraytemplate<typename _Tp > _If_sv< _Tp, int > compare (size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos) const noexcept(is_same< _Tp, __sv_type >::value)โ compare to astring_viewint compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos) constโ compare a substring to a substring, the deep-cut comparison ๐size_type copy (_CharT *__s, size_type __n, size_type __pos=0) constโ copy a substring into a C stringconst_reverse_iterator crbegin () const noexceptโ no blurb in the original, reverse const begin, she's backwards and proudconst_reverse_iterator crend () const noexceptโ matching reverse const endconst _CharT * data () const noexceptโ return a const pointer to the contents_CharT * data () noexceptโ return a non-const pointer to the contents ๐bool empty () const noexceptโ no blurb in the original, but she's checking if you're emptyiterator end ()โ the end iterator, also self-explanatoryconst_iterator end () const noexceptโ const end,noexceptbool ends_with (_CharT __x) const noexceptโ no blurb in the original, but yes she checks the endingbool ends_with (basic_string_view< _CharT, _Traits > __x) const noexceptโ same check,string_viewflavorbool ends_with (const _CharT *__x) const noexceptโ same check, C-string flavor
โจ erase + find (the search party) โจ
iterator erase (iterator __first, iterator __last)โ remove a range of charactersiterator erase (iterator __position)โ remove one characterbasic_string & erase (size_type __pos=0, size_type __n=npos)โ remove characterssize_type find (_CharT __c, size_type __pos=0) const noexceptโ find the position of a charactersize_type find (const _CharT *__s, size_type __pos, size_type __n) const noexceptโ find the position of a C substringsize_type find (const _CharT *__s, size_type __pos=0) const noexceptโ find the position of a C stringtemplate<typename _Tp > _If_sv< _Tp, size_type > find (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)โ find the position of astring_viewsize_type find (const basic_string &__str, size_type __pos=0) const noexceptโ find the position of a stringsize_type find_first_not_of (_CharT __c, size_type __pos=0) const noexceptโ find the position of a different charactersize_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptโ find the position of a character not in a C substringsize_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexceptโ find the position of a character not in a C stringtemplate<typename _Tp > _If_sv< _Tp, size_type > find_first_not_of (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)โ find the position of a character not in astring_viewsize_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexceptโ find the position of a character not in a stringsize_type find_first_of (_CharT __c, size_type __pos=0) const noexceptโ find the position of a charactersize_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptโ find the position of a character of a C substringsize_type find_first_of (const _CharT *__s, size_type __pos=0) const noexceptโ find the position of a character of a C stringtemplate<typename _Tp > _If_sv< _Tp, size_type > find_first_of (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value)โ find the position of a character of astring_viewsize_type find_first_of (const basic_string &__str, size_type __pos=0) const noexceptโ find the position of a character of a stringsize_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexceptโ find the last position of a different charactersize_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptโ find the last position of a character not in a C substringsize_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const noexceptโ find the last position of a character not in a C stringtemplate<typename _Tp > _If_sv< _Tp, size_type > find_last_not_of (const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)โ find the last position of a character not in astring_viewsize_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexceptโ find the last position of a character not in a stringsize_type find_last_of (_CharT __c, size_type __pos=npos) const noexceptโ find the last position of a charactersize_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const noexceptโ find the last position of a character of a C substring
okay bestie we're still deep in the member-function list and honestly? it's giving phonebook ๐ but every last one of these is a slay so let's keep going ๐
size_type find_last_of (const _CharT *__s, size_type __pos=npos) const noexceptโ finds the last position of a character from a C string ๐template<typename _Tp > _If_sv< _Tp, size_type > find_last_of (const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)โ finds the last position of a character from a string ๐ฆsize_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexceptโ finds the last position of a character from a string (yes, again, but from an actualbasic_stringthis time) โจreference front ()โ no description on this one, the manpage is being mysterious ๐const_reference front () const noexceptโ same entry,constflavour, still no description ๐allocator_type get_allocator () const noexceptโ hands you back a copy of the allocator that was used to construct this string ๐iterator insert (iterator __p, _CharT __c)โ inserts one character, that's it, that's the whole job ๐template<class _InputIterator > void insert (iterator __p, _InputIterator __beg, _InputIterator __end)โ inserts a whole range of characters ๐void insert (iterator __p, initializer_list< _CharT > __l)โ inserts aninitializer_listof characters, curly-brace girlies rise ๐ธvoid insert (iterator __p, size_type __n, _CharT __c)โ inserts multiple characters, one of them,__ntimes ๐basic_string & insert (size_type __pos, const _CharT *__s)โ inserts a C string ๐ซถbasic_string & insert (size_type __pos, const _CharT *__s, size_type __n)โ inserts a C substring โจtemplate<typename _Tp > _If_sv< _Tp, basic_string & > insert (size_type __pos, const _Tp &__svt)โ inserts astring_view๐basic_string & insert (size_type __pos, size_type __n, _CharT __c)โ inserts multiple characters (yep, this overload exists too, don't @ me) ๐template<typename _Tp > _If_sv< _Tp, basic_string & > insert (size_type __pos1, const _Tp &__svt, size_type __pos2, size_type __n=npos)โ inserts astring_viewbut you get to pick where the view starts and how much of it ๐ฆbasic_string & insert (size_type __pos1, const basic_string &__str)โ inserts the value of a string, iconic behaviour ๐basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n=npos)โ inserts a substring ๐ธsize_type length () const noexceptโ returns the number of characters in the string, not including any null-termination, lowkey the most relatable function here ๐size_type max_size () const noexceptโ returns thesize()of the biggest possible string, the theoretical maximum, main character energy ๐ฅoperator __sv_type () const noexceptโ converts to astring_view, glow-up complete โญbasic_string & operator+= (_CharT __c)โ appends a character ๐basic_string & operator+= (const _CharT *__s)โ appends a C string ๐template<typename _Tp > _If_sv< _Tp, basic_string & > operator+= (const _Tp &__svt)โ appends astring_view๐basic_string & operator+= (const basic_string &__str)โ appends a string to this string, friendship bracelet style ๐ซถbasic_string & operator+= (initializer_list< _CharT > __l)โ appends aninitializer_listof characters โจbasic_string & operator= (_CharT __c)โ sets the value to a string of length 1, tiny but mighty ๐basic_string & operator= (basic_string &&__str) noexcept(/*conditional */)โ move-assigns the value of__strinto this string ๐ฆbasic_string & operator= (const _CharT *__s)โ copies the contents of__sinto this string ๐template<typename _Tp > _If_sv< _Tp, basic_string & > operator= (const _Tp &__svt)โ sets the value to a string constructed from astring_view๐basic_string & operator= (const basic_string &__str)โ assigns the value of__strto this string ๐basic_string & operator= (initializer_list< _CharT > __l)โ sets the value to a string constructed from an initializer list ๐ธreference operator[] (size_type __pos)โ subscript access to the data contained in the string, the classic ๐๏ธconst_reference operator[] (size_type __pos) const noexceptโ subscript access to the data contained in the string, butconstandnoexcept, so it's extra composed about it โจvoid pop_back ()โ removes the last character. bye bestie ๐๐void push_back (_CharT __c)โ appends a single character, the itty bitty addition ๐reverse_iterator rbegin ()โ no description in the source, it's just out here existing ๐const_reverse_iterator rbegin () const noexceptโ theconsttwin, equally undescribed ๐ซถreverse_iterator rend ()โ also no description, living its truth ๐const_reverse_iterator rend () const noexceptโ and itsconstcounterpart, also just vibing ๐template<typename _Tp > _If_sv< _Tp, basic_string & > replace (const_iterator __i1, const_iterator __i2, const _Tp &__svt)โ replaces a range of characters with astring_view๐basic_string & replace (iterator __i1, iterator __i2, _CharT *__k1, _CharT *__k2)โ no description given, it's giving mystery ๐template<class _InputIterator > basic_string & replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)โ replaces a range of characters with a range โจbasic_string & replace (iterator __i1, iterator __i2, const _CharT *__k1, const _CharT *__k2)โ again, no description, the manpage said "figure it out" ๐basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s)โ replaces a range of characters with a C string ๐ธbasic_string & replace (iterator __i1, iterator __i2, const _CharT *__s, size_type __n)โ replaces a range of characters with a C substring ๐ฆbasic_string & replace (iterator __i1, iterator __i2, const basic_string &__str)โ replaces a range of characters with a string ๐basic_string & replace (iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2)โ no description, just signatures, we move ๐basic_string & replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l)โ replaces a range of characters with aninitializer_list๐basic_string & replace (iterator __i1, iterator __i2, iterator __k1, iterator __k2)โ no description either, the silence is loud ๐ญbasic_string & replace (iterator __i1, iterator __i2, size_type __n, _CharT __c)โ replaces a range of characters with multiple characters ๐template<typename _Tp > _If_sv< _Tp, basic_string & > replace (size_type __pos, size_type __n, const _Tp &__svt)โ replaces a range of characters with astring_view๐basic_string & replace (size_type __pos, size_type __n, const basic_string &__str)โ replaces characters with the value from another string โจbasic_string & replace (size_type __pos, size_type __n1, const _CharT *__s)โ replaces characters with the value of a C string ๐basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)โ replaces characters with the value of a C substring ๐ฆbasic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c)โ replaces characters with multiple characters ๐template<typename _Tp > _If_sv< _Tp, basic_string & > replace (size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos)โ replaces a range of characters with astring_view, with positions on both sides ๐basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2=npos)โ replaces characters with the value from another string ๐void reserve ()โ equivalent toshrink_to_fit(). yes, the no-arg one. that's what it says. no notes. ๐void reserve (size_type __res_arg)โ tries to preallocate enough memory for the specified number of characters ๐ฅvoid resize (size_type __n)โ resizes the string to the specified number of characters ๐void resize (size_type __n, _CharT __c)โ resizes the string to the specified number of characters, with a character to fill with ๐ธsize_type rfind (_CharT __c, size_type __pos=npos) const noexceptโ finds the last position of a character ๐size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const noexceptโ finds the last position of a C substring ๐ฆsize_type rfind (const _CharT *__s, size_type __pos=npos) const noexceptโ finds the last position of a C string โจtemplate<typename _Tp > _If_sv< _Tp, size_type > rfind (const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value)โ finds the last position of astring_view๐size_type rfind (const basic_string &__str, size_type __pos=npos) const noexceptโ finds the last position of a string ๐void shrink_to_fit () noexceptโ a non-binding request to reducecapacity()down tosize(), so it's a suggestion, not a command, respect its boundaries ๐ซถsize_type size () const noexceptโ returns the number of characters in the string, not including any null-termination, the moment of truth ๐bool starts_with (_CharT __x) const noexceptโ no description given, but the name is not subtle ๐bool starts_with (basic_string_view< _CharT, _Traits > __x) const noexceptโ also undescribed, also pretty self-explanatory ๐bool starts_with (const _CharT *__x) const noexceptโ third one, same energy โญbasic_string substr (size_type __pos=0, size_type __n=npos) constโ gets you a substring, the little slice of the original ๐ฐvoid swap (basic_string &__s) noexcept(/*conditional */)โ swaps contents with another string, consensual and mutual obviously ๐
โจ Static Public Attributes โจ
static const size_type nposโ the value returned by various member functions when they fail ๐ญ literally the "idk bestie, didn't find it" of the string world.
๐ Protected Types ๐
typedef iterator __const_iteratorโ that's the whole entry, no extra lore ๐ธ
๐ 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 mission statement, and it ate ๐
Since โ C++98. an elder. a legend. respect the elders ๐ซถ
๐ Template Parameters ๐
_CharTโ type of character ๐_Traitsโ traits for the 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 โ so like, not everything optional is on the menu, just those three โจ
Todo โ Needs documentation! See http://gcc.gnu.org/onlinedocs/libstdc++/manual/documentation_style.html ๐ญ the todo is literally "document this", iconic honesty.
Documentation? What's that? โ Nathan Myers ncm@cantrip.org. a real quote, from a real person, and honestly? same energy ๐ซถ
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
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, subtract one, that's the trick, it's giving "the header is hiding right behind the vibes" ๐ต๏ธ
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. one allocation. one. that's the whole flex ๐
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.) โ that's their note, not mine, I'm just delivering it ๐ซก
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 ๐ง no cap, zero means one here, that's not a typo, that's the encoding.
All but the last paragraph is considered pretty conventional for a Copy-On-Write C++ string implementation ๐ and that's the vibe check on the internal layout, bestie.
๐ CONSTRUCTOR & DESTRUCTOR DOCUMENTATION ๐
okay bestie, this is the part where we meet every single way you can birth a std::basic_string. there are a LOT of them. like, an unreasonable amount. but each one is iconic in its own way, so let's go ๐ซถ
๐ the default girlie: basic_string()
template<typename _CharT , typename _Traits , typename _Alloc >
std::basic_string< _CharT, _Traits, _Alloc >::basic_string () [inline],
[noexcept]
Default constructor, and she creates an empty string. that's it, that's the whole vibe. no cap. it's [noexcept] too, so she will not be throwing hands ๐
Referenced by std::basic_string< _CharT, _Traits, _Alloc >::substr().
๐ง the allocator one: basic_string(const _Alloc & __a)
template<typename _CharT , typename _Traits , typename _Alloc >
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _Alloc
& __a) [inline], [explicit]
Construct an empty string, but using allocator __a. note the [explicit] bestie โ she does not do sneaky conversions, you have to mean it โจ
๐ฆ the copy ctor: basic_string(const basic_string & __str)
template<typename _CharT , typename _Traits , typename _Alloc >
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const
basic_string< _CharT, _Traits, _Alloc > & __str) [inline]
Construct a string with a copy of the value of __str. so like... a whole new string, same energy ๐
Parameters
__strโ source string. the original. the blueprint.
๐ธ copy-a-substring, allocator edition
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 a string as a copy of a substring. you're taking a slice, but make it fashion ๐
Parameters
__strโ source string.__posโ index of the first character to copy from.__aโ allocator to use.
๐ copy-a-substring, with a 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)
Construct a string as a copy of a substring โ this time you're also telling it exactly how many characters you want.
Parameters
__strโ source string.__posโ index of the first character to copy from.__nโ number of characters to copy.
๐ง copy-a-substring, with a length and an 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)
Construct a string as a copy of a substring โ the full package: position, length, allocator. she has everything ๐ญ๐
Parameters
__strโ source string.__posโ index of the first character to copy from.__nโ number of characters to copy.__aโ allocator to use.
๐ฅ from a character array: basic_string(const _CharT * __s, size_type __n, const _Alloc & __a = _Alloc())
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 a 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, and'\0'has no special meaning here. read that again, bestie โ no sneaky null-terminator behaviour, she will read right past it ๐
โญ from a C string: the _RequireAllocator 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]
Construct a string as a copy of a C string. this one does respect the C-string rules, iykyk ๐
Parameters
__sโ source C string.__aโ allocator to use (default is default allocator).
๐ fill it up: basic_string(size_type __n, _CharT __c, const _Alloc & __a = _Alloc())
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 a string as multiple characters โ same character, __n times. it's giving "repeated emoji" energy ๐๐๐
Parameters
__nโ number of characters.__cโ character to use.__aโ allocator to use (default is default allocator).
๐ฆ the move ctor: basic_string(basic_string && __str)
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. she's [noexcept], she's efficient, she's that girl โจ
Parameters
__strโ source string.
The newly-created string contains the exact contents of __str. after the move, __str is a valid, but unspecified string. so like... she's still alive, she's just not telling you what she's wearing anymore ๐
๐ from an initializer list
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. brace-init besties rise ๐ซถ
Parameters
__lโstd::initializer_listof characters.__aโ allocator to use (default is default allocator).
๐ง from an iterator range
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 a copy of a range. give her a begin and an end and she'll handle the rest ๐
Parameters
__begโ start of range.__endโ end of range.__aโ allocator to use (default is default allocator).
๐ฎ substring of a string_view-convertible thing
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp , typename = enable_if_t<is_convertible_v<const
_Tp&, __sv_type>>> std::basic_string< _CharT, _Traits, _Alloc
>::basic_string (const _Tp & __t, size_type __pos, size_type __n, const
_Alloc & __a = _Alloc()) [inline]
Construct string from a substring of a string_view. yes the template constraint is unhinged, no we're not scared of it ๐ญ
Parameters
__tโ source object convertible to string view.__posโ the index of the first character to copy from__t.__nโ the number of characters to copy from__t.__aโ allocator to use.
๐ from a string_view, the explicit one
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp , typename = _If_sv<_Tp, void>>
std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _Tp &
__t, const _Alloc & __a = _Alloc()) [inline], [explicit]
Construct string from a string_view. flagged [explicit] so nobody converts by accident โ consent matters, bestie ๐ซถ
Parameters
__tโ source object convertible to string view.__aโ allocator to use (default is default allocator).
๐ the end of an era: ~basic_string()
template<typename _CharT , typename _Traits , typename _Alloc >
std::basic_string< _CharT, _Traits, _Alloc >::~basic_string () [inline],
[noexcept]
Destroy the string instance. goodbye queen, you served ๐
[noexcept] so she leaves peacefully.
References std::basic_string< _CharT, _Traits, _Alloc >::get_allocator().
๐ MEMBER FUNCTION DOCUMENTATION ๐
๐ง __resize_and_overwrite (the non-standard one)
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. yes the double underscore is right there in the name โ she's an internal icon, not a public one ๐
๐ธ append(_InputIterator __first, _InputIterator __last)
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. appends characters in the range [__first,__last) to this string ๐ฅ
Parameters
__firstโ iterator referencing the first character to append.__lastโ iterator marking the end of the range.
Returns โ reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐ฆ append(const _CharT * __s)
template<typename _CharT , typename _Traits , typename _Alloc > basic_string
& std::basic_string< _CharT, _Traits, _Alloc >::append (const _CharT *
__s) [inline]
Append a C string. classic. reliable. never misses โจ
Parameters
__sโ the C string to append.
Returns โ reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
๐ append(const _CharT * __s, size_type __n)
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)
Append a C substring โ the C string's cousin who actually tells you how many characters she's bringing ๐
Parameters
__sโ the C string to append.__nโ the number of characters to append.
Returns โ reference to this string.
References std::size().
๐ง append(const _Tp & __svt)
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string<
_CharT, _Traits, _Alloc >::append (const _Tp & __svt) [inline]
Append a string_view โ well, append anything convertible to one ๐ซถ
Parameters
__svtโ the object convertible tostring_viewto be appended.
Returns โ reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
๐ append(const _Tp & __svt, size_type __pos, size_type __n = npos)
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string<
_CharT, _Traits, _Alloc >::append (const _Tp & __svt, size_type __pos,
size_type __n = npos) [inline]
Append a range of characters from a string_view. note the default __n = npos โ she'll take as much as she can unless you say otherwise ๐
Parameters
__svtโ the object convertible tostring_viewto be appended from.__posโ the position in thestring_viewto append from.__nโ the number of characters to append from thestring_view.
Returns โ reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
๐ฅ append(const basic_string & __str)
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)
Append a string to this string. the main character overload, fr fr ๐
Parameters
__strโ the string to append.
Returns โ reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::size(), and std::size().
Referenced by std::basic_string< _CharT, _Traits, _Alloc >::append(), std::basic_string< _CharT, _Traits, _Alloc >::append(), std::basic_string< _CharT, _Traits, _Alloc >::append(), std::basic_string< _CharT, _Traits, _Alloc >::append(), std::collate< _CharT >::do_transform(), std::basic_string< _CharT, _Traits, _Alloc >::operator+=(), std::basic_string< _CharT, _Traits, _Alloc >::operator+=(), std::basic_string< _CharT, _Traits, _Alloc >::operator+=(), std::basic_string< _CharT, _Traits, _Alloc >::operator+=(), and std::operator>>().
(yes, append() appears four times and operator+=() appears four times in that list. that's literally what the page says, bestie โ we do not editorialise ๐)
๐ append(const basic_string & __str, size_type __pos, size_type __n = npos)
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)
Append a substring. this is the one with rules, so listen up ๐ซถ
Parameters
__strโ the string to append.__posโ index of the first character ofstrto append.__nโ the number of characters to append.
Returns โ reference to this string.
Exceptions
std::out_of_rangeif__posis not a valid index.
This function appends __n characters from __str starting at __pos to this string. If __n is is larger than the number of available characters in __str, the remainder of __str is appended. (and yes, "is is" is in the original โ she's quirky like that ๐ญ)
References std::size().
โญ append(initializer_list< _CharT > __l)
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. curly braces gang, we stay winning ๐
Parameters
__lโ theinitializer_listof characters to append.
Returns โ reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
๐ append(size_type __n, _CharT __c)
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string< _CharT, _Traits, _Alloc > & std::basic_string< _CharT,
_Traits, _Alloc >::append (size_type __n, _CharT __c)
Append multiple characters โ one character, __n copies of it. the "spam the same emoji" pipeline ๐๐๐
Parameters
__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. ๐
๐ References std::size().
๐ฆ assign โ the iterator-range glow-up
template<typename _CharT , typename _Traits , typename _Alloc >
template<class _InputIterator >
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(_InputIterator __first, _InputIterator __last) [inline]
Bestie, this one sets the value of your string to a whole range of characters. Iconic behaviour, no notes. โจ
Parameters
__firstโ iterator pointing at the first character to append.__lastโ iterator marking the end of the range.
Returns โ a reference to this string, so you can keep chaining like the main character you are.
Sets the value of the string to the characters in the range [__first,__last).
๐ References std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐
assign โ move edition, the speedy one
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(basic_string< _CharT, _Traits, _Alloc > && __str) [inline], [noexcept]
Grabs the contents of another string and makes them yours. Marked [noexcept] so it literally cannot throw at you โ a whole vibe. ๐ฅ
Parameters
__strโ the source string to use.
Returns โ reference to this string. ๐ซถ
So here's the tea: this function sets this string to the exact contents of __str. After that, __str is a valid, but unspecified string โ meaning it still, like, exists and everything, it's just not telling you what's in it anymore. ๐
๐ References std::basic_string< _CharT, _Traits, _Alloc >::swap().
๐ธ assign โ from a C string
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(const _CharT * __s) [inline]
Parameters
__sโ the C string to use.
Returns โ reference to this string, bestie.
This sets the value of this string to the value of __s. And the data is copied, so once the function returns there's zero dependence on __s โ you can free it, scribble on it, do whatever, the string already has its own copy. ๐
๐ References std::basic_string< _CharT, _Traits, _Alloc >::assign().
๐ง assign โ C substring, take __n characters
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)
Parameters
__sโ the C string to use.__nโ number of characters to use.
Returns โ reference to this string. ๐
Sets the value of this string to the first __n characters of __s. And if __n is larger than the number of available characters in __s? Then the remainder of __s is used. It just takes what it can get, honestly relatable. ๐
๐ References std::size().
๐ assign โ from a string_view
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp >
_If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::assign
(const _Tp & __svt) [inline]
Parameters
__svtโ the source object convertible tostring_view.
Returns โ reference to this string. โจ
Note the return type: _If_sv< _Tp, basic_string & > โ that's the little SFINAE gatekeeper making sure __svt really is convertible to a string_view before this overload even shows up. Gatekeeping, but make it template magic. ๐
๐ References std::basic_string< _CharT, _Traits, _Alloc >::assign().
๐ assign โ from a range inside a string_view
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp >
_If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::assign
(const _Tp & __svt, size_type __pos, size_type __n = npos) [inline]
Parameters
__svtโ the source object convertible tostring_view.__posโ the position in thestring_viewto assign from.__nโ the number of characters to assign. Defaults tonpos, which is the "just give me everything from here" default. ๐
Returns โ reference to this string.
๐ References std::basic_string< _CharT, _Traits, _Alloc >::assign().
๐ assign โ copy from another string
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string< _CharT, _Traits, _Alloc > &
std::basic_string< _CharT, _Traits, _Alloc >::assign
(const basic_string< _CharT, _Traits, _Alloc > & __str)
Parameters
__strโ the source string to use.
Returns โ reference to this string. ๐ซถ
The plain old "set value to contents of another string" moment. Nothing flashy, just reliable. And this one is a very popular function internally โ literally everybody's referencing it:
Referenced by:
std::basic_string< _CharT, _Traits, _Alloc >::assign()ร5 (yes, five of them โ the overloads all lean on this one)std::basic_string< _CharT, _Traits, _Alloc >::operator=()ร5std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow()std::basic_stringbuf< _CharT, _Traits, _Alloc >::str()std::basic_stringbuf< _CharT, _Traits, _Alloc >::str()(again โ two of them)
๐ References std::basic_string< _CharT, _Traits, _Alloc >::get_allocator().
๐ assign โ substring of a string, with the pos/n dance
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]
Parameters
__strโ the string to use.__posโ index of the first character ofstr.__nโ number of characters to use. Defaults tonpos. โจ
Returns โ reference to this string.
Exceptions โ std::out_of_range if pos is not a valid index. So like, behave. ๐ญ
Sets this string to the substring of __str consisting of __n characters at __pos. If __n is larger than the number of available characters in __str, the remainder of __str is used โ it's flexible like that, lowkey generous.
๐ References std::basic_string< _CharT, _Traits, _Alloc >::assign().
๐ธ assign โ initializer_list moment
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(initializer_list< _CharT > __l) [inline]
Parameters
__lโ theinitializer_listof characters to assign.
Returns โ reference to this string. ๐
Brace-init your way into a string's soul, iykyk.
๐ References std::basic_string< _CharT, _Traits, _Alloc >::assign().
๐ assign โ repeat a character __n times
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string & std::basic_string< _CharT, _Traits, _Alloc >::assign
(size_type __n, _CharT __c) [inline]
Parameters
__nโ length of the resulting string.__cโ the character to use.
Returns โ reference to this string.
Sets the value of this string to __n copies of character __c. It's giving "spam one emoji until it becomes a personality". ๐ฆ
๐ References std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ฅ at โ the safe one (non-const)
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, but likeโฆ responsibly. ๐
Parameters
__nโ the index of the character to access.
Returns โ read/write reference to the character.
Exceptions โ std::out_of_range if n is an invalid index. ๐จ
This function provides for safer data access. The parameter is first checked to make sure it's actually in the range of the string. If the check fails, the function throws out_of_range. And on success? Success results in unsharing the string. Noted, bestie โ that's a real side effect, not just a vibe.
๐ References std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ง at โ the safe one, but const
template<typename _CharT , typename _Traits , typename _Alloc >
const_reference std::basic_string< _CharT, _Traits, _Alloc >::at
(size_type __n) const [inline]
Parameters
__nโ the index of the character to access.
Returns โ read-only (const) reference to the character.
Exceptions โ std::out_of_range if n is an invalid index. ๐ญ
Same safer-data-access situation: the parameter is checked against the range of the string first, and if the check fails it throws out_of_range. Look at you doing bounds-checking like a responsible adult. ๐ซถ
๐ References std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ back โ last character, read/write
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. Main character energy, literally the final girl of the string. ๐
๐ References std::basic_string< _CharT, _Traits, _Alloc >::empty(), std::basic_string< _CharT, _Traits, _Alloc >::operator[](), and std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ง back โ last character, const
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. And it's [noexcept], so it's not gonna pop off with an exception. ๐
๐ References std::basic_string< _CharT, _Traits, _Alloc >::empty(), std::basic_string< _CharT, _Traits, _Alloc >::operator[](), and std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ begin โ iterator to the first character, read/write
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. And heads up: unshares the string. โจ
Referenced by: std::basic_string< _CharT, _Traits, _Alloc >::crend(), std::regex_match() (ร2), std::regex_replace() (ร2), std::regex_search(), std::basic_string< _CharT, _Traits, _Alloc >::rend() (ร2), and std::basic_string< _CharT, _Traits, _Alloc >::replace().
The regex girlies stay calling on this one, no cap.
๐ง begin โ iterator to the first character, const
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. [noexcept] too โ calm, collected, throwing nothing. ๐ซถ
๐ c_str โ the classic
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. ๐ฆ
โ ๏ธ Okay bestie, listen: this is a handle to internal data. Do not modify it or dire things may happen. I'm serious. Do not touch. ๐
Referenced by: std::collate< _CharT >::do_compare(), std::money_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get() (ร3), std::collate< _CharT >::do_transform(), std::basic_filebuf< _CharT, _Traits >::open(), std::regex_replace(), and std::experimental::filesystem::v1::filesystem_error::what().
๐ capacity โ how much room before reallocation
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. It's the "how much space do I have in my bag before I have to check it" of functions. ๐
Referenced by: std::basic_string< _CharT, _Traits, _Alloc >::push_back().
๐ง 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], [noexcept]
Returns a read-only (constant) iterator that points to the first character in the string. Yes it's basically begin() const, but the c is for commitment. ๐
๐ 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], [noexcept]
Returns a read-only (constant) iterator that points one past the last character in the string. Your classic half-open-range ending, standing just outside the party like a bodyguard. ๐ซถ
๐ References std::basic_string< _CharT, _Traits, _Alloc >::size().
clear() ๐งน
template<typename _CharT , typename _Traits , typename _Alloc > void
std::basic_string< _CharT, _Traits, _Alloc >::clear () [inline],
[noexcept]
okay bestie, this one is SO simple and so satisfying โ it erases the string, making it empty. that's it. that's the whole vibe. your string goes from main character to absolutely nothing โจ
it's [inline] and [noexcept], so it's fast and it will never, ever throw at you. love that for us ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::get_allocator().
Referenced by: std::basic_stringbuf< _CharT, _Traits, _Alloc >::setbuf().
compare() โ the overload that checks you against a C string ๐
template<typename _CharT , typename _Traits , typename _Alloc > int
std::basic_string< _CharT, _Traits, _Alloc >::compare (const _CharT *
__s) const [inline], [noexcept]
literally the "who's better, me or that C string?" function. it's [inline] and [noexcept] โ no drama, no throws ๐
Parameters
__sโ the C string you're comparing against.
Returns
- Integer
< 0,0, or> 0.
so it 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. and how does it decide? it determines the effective length rlen of the strings to compare as the smallest of size() and the length of a string constructed from __s. then 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. iconic tie-break behaviour, ngl ๐
References: std::min(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
compare() โ the string_view one ๐ฆ
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, int > std::basic_string< _CharT,
_Traits, _Alloc >::compare (const _Tp & __svt) const [inline],
[noexcept]
same energy, but against a string_view. [inline], [noexcept], chef's kiss ๐
Parameters
__svtโ an object convertible tostring_viewto compare against.
Returns
- Integer
< 0,0, or> 0.
References: std::min(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
compare() โ the string-to-string classic ๐
template<typename _CharT , typename _Traits , typename _Alloc > int
std::basic_string< _CharT, _Traits, _Alloc >::compare (const
basic_string< _CharT, _Traits, _Alloc > & __str) const [inline]
comparing a string to a string. the original. the blueprint. [inline] and no [noexcept] listed here, fyi ๐
Parameters
__strโ the 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. the effective length is determined as the smallest of size() and str.size(), then it compares the two strings by calling traits::compare(data(), str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. periodt ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::data(), std::min(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
compare() โ substring vs. a string_view ๐ธ
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, int > std::basic_string< _CharT,
_Traits, _Alloc >::compare (size_type __pos, size_type __n, const _Tp &
__svt) const [inline], [noexcept]
now we're slicing. [inline] + [noexcept] obviously ๐ซถ
Parameters
__posโ a position in the string to start comparing from.__nโ the number of characters to compare.__svtโ an object convertible tostring_viewto compare against.
Returns
- Integer
< 0,0, or> 0.
compare() โ substring vs. a full string โ๏ธ
template<typename _CharT , typename _Traits , typename _Alloc > int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str)
const [inline]
Parameters
__posโ index of first character of substring.__nโ number of characters in substring.__strโ the string to compare against.
Returns
- Integer
< 0,0, or> 0.
the whole deal: form the substring of this string from the __n characters starting at __pos. then 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. effective length rlen is the smallest of the length of the substring and __str.size(). then it compares the two strings by calling traits::compare(substring.data(),str.data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. no cap, this is the good stuff ๐ฅ
References: std::basic_string< _CharT, _Traits, _Alloc >::data(), std::min(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
compare() โ substring vs. C string ๐
template<typename _CharT , typename _Traits , typename _Alloc > int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s) const [inline]
Parameters
__posโ index of first character of substring.__n1โ number of characters in substring.__sโ the C string to compare against.
Returns
- Integer
< 0,0, or> 0.
Form the substring of this string from the __n1 characters starting at pos. (yes, the docs say pos there โ copying the manpage's words exactly, bestie, don't come for me ๐ญ) 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. effective length rlen = the smallest of the length of the substring and the length of a string constructed from __s. then 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. ๐
References: std::min().
compare() โ substring vs. character array ๐
template<typename _CharT , typename _Traits , typename _Alloc > int
std::basic_string< _CharT, _Traits, _Alloc >::compare (size_type __pos,
size_type __n1, const _CharT * __s, size_type __n2) const [inline]
Parameters
__posโ index of first character of substring.__n1โ number of characters in substring.__sโ the 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. then 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. effective length rlen = the smallest of the length of the substring and __n2. then 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. โ ๏ธ read that twice, bestie โ a null terminator does NOT save you here.
References: std::min().
compare() โ substring vs. string_view with a start pos ๐ซ
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, int > std::basic_string< _CharT,
_Traits, _Alloc >::compare (size_type __pos1, size_type __n1, const _Tp
& __svt, size_type __pos2, size_type __n2 = npos) const [inline],
[noexcept]
double-slicing, double the fun โจ [inline] + [noexcept], and __n2 defaults to npos.
Parameters
__pos1โ a position in the string to start comparing from.__n1โ the number of characters to compare.__svtโ an object convertible tostring_viewto compare against.__pos2โ a position in thestring_viewto start comparing from.__n2โ the number of characters to compare.
Returns
- Integer
< 0,0, or> 0.
compare() โ substring vs. substring, the final boss ๐๐
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]
Parameters
__pos1โ index of first character of substring.__n1โ number of characters in substring.__strโ the string to compare against.__pos2โ index of first character of substring ofstr.__n2โ number of characters in substring ofstr.
Returns
- Integer
< 0,0, or> 0.
here's the tea: 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. then 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. effective length rlen = the smallest of the lengths of the substrings. then the function then compares the two strings by calling traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). If the result of the comparison is nonzero returns it, otherwise the shorter one is ordered first. ate and left no crumbs ๐ฅ
References: std::basic_string< _CharT, _Traits, _Alloc >::data(), and std::min().
copy() โ steal a chunk 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
copy substring into C string, no null-terminator shenanigans implied โ you get raw characters, bestie ๐
Parameters
__sโ the C string to copy value into.__nโ number of characters to copy.__posโ index of first character to copy.
note that __pos has a default of 0 โ so if you don't say where to start, it starts at the beginning like a well-behaved icon โจ
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. so likeโฆ watch your indexes, okay? ๐ญ
crbegin() โ backwards but make it read-only ๐
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. lowkey the cutest way to walk a string backwards ๐ฆ [inline], [noexcept], const-correct, flawless.
References: std::basic_string< _CharT, _Traits, _Alloc >::end().
crend() โ the backwards end-of-the-line ๐
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. it's the pairing to crbegin() โ one before the first character, which is exactly the "stop here" marker for a reverse loop ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::begin().
data() โ gimme the pointer, but const ๐ซถ
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.
โ ๏ธ undefined behaviour alert โ do NOT write through this pointer. it's giving "look, don't touch" ๐
To get a pointer that allows modifying the contents use &str[0] instead, (or in C++17 the non-const str.data() overload). there's your workaround, bestie, you're welcome ๐
std::basic_regex< _Ch_type, _Rx_traits >::assign()std::basic_string< _CharT, _Traits, _Alloc >::compare()std::basic_string< _CharT, _Traits, _Alloc >::compare()std::basic_string< _CharT, _Traits, _Alloc >::compare()std::collate< _CharT >::do_compare()std::collate< _CharT >::do_transform()std::basic_string< _CharT, _Traits, _Alloc >::find()std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of()std::basic_string< _CharT, _Traits, _Alloc >::find_first_of()std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of()std::basic_string< _CharT, _Traits, _Alloc >::find_last_of()std::match_results< _Bi_iter, _Alloc >::format()std::basic_string< _CharT, _Traits, _Alloc >::operator __sv_type()std::basic_string< _CharT, _Traits, _Alloc >::rfind()std::basic_stringbuf< _CharT, _Traits, _Alloc >::str()std::regex_traits< _Ch_type >::transform()
๐ซถ data() โ the non-const glow-up
template<typename _CharT , typename _Traits , typename _Alloc > _CharT *
std::basic_string< _CharT, _Traits, _Alloc >::data () [inline], [noexcept]
Okay bestie, this is the non-const version of data(), and it's giving main character energy โจ It hands you back a pointer to the character sequence that the string is literally holding. And yes โ modifying the characters in that sequence is allowed. Go off. ๐
๐ฆ empty() โ is it literally nothing
template<typename _CharT , typename _Traits , typename _Alloc > bool
std::basic_string< _CharT, _Traits, _Alloc >::empty () const [inline],
[noexcept]
Returns true if the string is empty. That's it, that's the whole vibe. Equivalent to *this == ''. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::size()
Referenced by:
std::basic_string< _CharT, _Traits, _Alloc >::back()std::basic_string< _CharT, _Traits, _Alloc >::back()std::basic_string< _CharT, _Traits, _Alloc >::front()std::basic_string< _CharT, _Traits, _Alloc >::front()std::tr2::operator>>()std::basic_string< _CharT, _Traits, _Alloc >::pop_back()
๐ง end() (the spicy read/write one)
template<typename _CharT , typename _Traits , typename _Alloc > iterator
std::basic_string< _CharT, _Traits, _Alloc >::end () [inline]
Slides you a read/write iterator that points one past the last character in the string. And lowkey important: it unshares the string. Not me warning you โ it's right there in the docs, iykyk. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::size()
Referenced by:
std::basic_string< _CharT, _Traits, _Alloc >::crbegin()std::basic_string< _CharT, _Traits, _Alloc >::rbegin()std::basic_string< _CharT, _Traits, _Alloc >::rbegin()std::regex_match()std::regex_match()std::regex_replace()std::regex_replace()std::regex_search()
๐ end() const โ the chill read-only twin
template<typename _CharT , typename _Traits , typename _Alloc >
const_iterator std::basic_string< _CharT, _Traits, _Alloc >::end ()
const [inline], [noexcept]
Same one-past-the-last-character energy, but read-only (constant) this time. No touching, just looking. Respect the boundary bestie. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::size()
๐ erase() โ the range version (be careful, this eats characters)
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string< _CharT, _Traits, _Alloc >::iterator std::basic_string<
_CharT, _Traits, _Alloc >::erase (iterator __first, iterator __last)
Remove a range of characters. Poof. Gone. ๐ญ
Parameters:
__firstโ iterator referencing the first character to remove.__lastโ iterator referencing the end of the range.
Returns: an iterator referencing the location of the first character after removal.
So it removes the characters in the range [first,last) from this string. And here's the reassure-her moment: the value of the string doesn't change if an error is thrown. Safe-ish. ๐ซถ
๐ธ erase() โ the single-character version
template<typename _CharT , typename _Traits , typename _Alloc > iterator
std::basic_string< _CharT, _Traits, _Alloc >::erase (iterator
__position) [inline]
Remove one character. Just the one. Petty and precise. ๐
Parameters:
__positionโ iterator referencing the character to remove.
Returns: an iterator referencing the same location after removal.
Removes the character at __position from this string. And same deal as before: the value of the string doesn't change if an error is thrown. โจ
๐ฅ erase() โ the index-and-count version
template<typename _CharT , typename _Traits , typename _Alloc > basic_string
& std::basic_string< _CharT, _Traits, _Alloc >::erase (size_type __pos =
0, size_type __n = npos) [inline]
Remove characters. Plural. The full sweep. ๐
Parameters:
__posโ index of the first character to remove (default0).__nโ number of characters to remove (default remainder).
Returns: a reference to this string.
Exceptions: std::out_of_range if pos is beyond the end of this string.
So what it does: removes __n characters from this string starting at __pos. The length of the string is reduced by __n. If there are fewer than __n characters to remove, the remainder of the string is truncated. If __p is beyond the end of the string, out_of_range is thrown. And yes, the value of the string doesn't change if an error is thrown. ๐
ngl, that __p in the exception note is exactly how the page spells it โ not a typo on my end, I'm just repeating it fr fr.
Referenced by:
std::getline()std::operator>>()std::basic_string< _CharT, _Traits, _Alloc >::pop_back()
๐ find() โ locating a single character
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string<
_CharT, _Traits, _Alloc >::find (_CharT __c, size_type __pos = 0) const
[noexcept]
Find the position of a character. Detective mode activated ๐
Parameters:
__cโ character to locate.__posโ index of the character to search from (default0).
Returns: index of the first occurrence.
Starting from __pos, it searches forward for __c within this string. If it's found, you get the index where it was found. If not found โ you get npos. (Cruel but fair. ๐)
References: std::size()
๐ find() โ locating a C substring
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string<
_CharT, _Traits, _Alloc >::find (const _CharT * __s, size_type __pos,
size_type __n) const [noexcept]
Find the position of a C substring. Very demure, very _CharT *. โจ
Parameters:
__sโ C string to locate.__posโ index of the character to search from.__nโ number of characters fromsto search for.
Returns: index of the start of the first occurrence.
Starting from __pos, it searches forward for the first __n characters in __s within this string. If found, you get the index where it begins. If not found, npos. ๐
References: std::data(), std::size()
Referenced by:
std::basic_string< _CharT, _Traits, _Alloc >::find()std::basic_string< _CharT, _Traits, _Alloc >::find()std::basic_string< _CharT, _Traits, _Alloc >::find()std::basic_string< _CharT, _Traits, _Alloc >::find_first_of()
๐ find() โ locating a whole C string
template<typename _CharT , typename _Traits , typename _Alloc > size_type
std::basic_string< _CharT, _Traits, _Alloc >::find (const _CharT * __s,
size_type __pos = 0) const [inline], [noexcept]
Find the position of a C string. The whole thing, no substring slicing. ๐ซถ
Parameters:
__sโ C string to locate.__posโ index of the character to search from (default0).
Returns: index of the start of the first occurrence.
Starting from __pos, it searches forward for the value of __s within this string. Found it? You get the index where it begins. Didn't find it? npos, bestie. ๐ญ
References: std::basic_string< _CharT, _Traits, _Alloc >::find()
๐ง find() โ the string_view-convertible version
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, size_type > std::basic_string<
_CharT, _Traits, _Alloc >::find (const _Tp & __svt, size_type __pos = 0)
const [inline], [noexcept]
Find the position of a string_view. Very modern of her, honestly obsessed. ๐
Parameters:
__svtโ the object convertible tostring_viewto locate.__posโ index of the character to search from (default0).
Returns: index of the start of the first occurrence.
References: std::basic_string< _CharT, _Traits, _Alloc >::find()
๐ find() โ the full basic_string version (the classic)
template<typename _CharT , typename _Traits , typename _Alloc > size_type
std::basic_string< _CharT, _Traits, _Alloc >::find (const basic_string<
_CharT, _Traits, _Alloc > & __str, size_type __pos = 0) const [inline],
[noexcept]
Find the position of a string. The OG. The main event. ๐
Parameters:
__strโ string to locate.__posโ index of the character to search from (default0).
Returns: index of the start of the first occurrence.
Starting from __pos, it searches forward for the value of __str within this string. If found, you get the index where it begins. If not found, npos. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::find(), std::basic_string< _CharT, _Traits, _Alloc >::size()
๐ฆ find_first_not_of() โ the character with "not like the others" energy
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string<
_CharT, _Traits, _Alloc >::find_first_not_of (_CharT __c, size_type
__pos = 0) const [noexcept]
Find the position of a different character. The one that refused to match the group chat. ๐
Parameters:
__cโ character to avoid.__posโ index of the character to search from (default0).
Returns: index of the first occurrence.
Starting from __pos, it searches forward for a character other than __c within this string. If found, you get the index where it was found. If not found, npos. ๐ญ
References: std::size()
๐ธ find_first_not_of() โ the C substring version
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string<
_CharT, _Traits, _Alloc >::find_first_not_of (const _CharT * __s,
size_type __pos, size_type __n) const [noexcept]
Find the position of a character not in a C substring. Niche? Maybe. Iconic? Absolutely. โจ
Parameters:
__sโ C string containing characters to avoid.__posโ index of the character to search from.__nโ number of characters from__sto consider.
Returns: index of the first occurrence.
Starting from __pos, it searches forward for a character not contained in the first __n characters of __s within this string. If found, you get the index where it was found. If not found โ npos, as always. ๐ซถ
References: std::size()
๐ find_first_not_of() โ the C string version
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 the position of a character not in a C string. Same vibe, whole string, no __n shenanigans. ๐
Parameters:
__sโ C string containing characters to avoid.__posโ index of the character to search from (default0).
Returns: index of the first occurrence.
Starting from __pos, it searches forward for a character not contained in __s within this string. If found, you get the index where it was found. If not found, npos. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of()
๐ find_first_not_of() โ the string_view-convertible version
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, size_type > std::basic_string<
_CharT, _Traits, _Alloc >::find_first_not_of (const _Tp & __svt,
size_type __pos = 0) const [inline], [noexcept]
Find the position of a character not in a string_view. The most spoiled-for-choice overload of the bunch, and she deserves it. ๐
Parameters:
__svtโ an object convertible tostring_viewcontaining characters to avoid.__posโ index of the character to search from (default0).
Returns: index of the first occurrence.
References: std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of()
๐ธ find_first_not_of โ the string-flavored 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], [noexcept]
Find position of a character not in string. Like, whereโs the first little icon that isnโt part of the squad?
- 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.
- References
std::basic_string< _CharT, _Traits, _Alloc >::data(),std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of(), andstd::basic_string< _CharT, _Traits, _Alloc >::size(). - Referenced by
std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of(),std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of(), andstd::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of().
๐ find_first_of โ single character edition
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. One specific character. Main character energy, but make it a _CharT.
- 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).
- References
std::basic_string< _CharT, _Traits, _Alloc >::find().
๐ find_first_of โ C substring 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 [noexcept]
Find position of a character of C substring. Youโre giving it a C-style string and a character count, bestie. Very โhereโs exactly how much of this thing to look at.โ
- 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
std::size().
๐ฆ find_first_of โ C string edition
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. Same quest, but the C string runs the whole group chat.
- 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.
- References
std::basic_string< _CharT, _Traits, _Alloc >::find_first_of().
๐ find_first_of โ string_view-ish edition
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, size_type > std::basic_string<
_CharT, _Traits, _Alloc >::find_first_of (const _Tp & __svt, size_type
__pos = 0) const [inline], [noexcept]
Find position of a character of a string_view. Itโs giving โI accept anything convertible to string_view, and Iโm not sorry.โ
- Parameters
__svtโ An object convertible tostring_viewcontaining characters to locate.__posโ Index of character to search from (default0).
- Returns โ Index of first occurrence.
- References
std::basic_string< _CharT, _Traits, _Alloc >::find_first_of().
๐ซถ find_first_of โ string edition
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. Now the characters to locate are coming from another basic_string, which is lowkey the classic bestie move.
- 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.
- References
std::basic_string< _CharT, _Traits, _Alloc >::data(),std::basic_string< _CharT, _Traits, _Alloc >::find_first_of(), andstd::basic_string< _CharT, _Traits, _Alloc >::size(). - Referenced by
std::basic_string< _CharT, _Traits, _Alloc >::find_first_of(),std::basic_string< _CharT, _Traits, _Alloc >::find_first_of(), andstd::basic_string< _CharT, _Traits, _Alloc >::find_first_of().
๐
find_last_not_of โ single character 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 (_CharT __c, size_type __pos
= npos) const [noexcept]
Find last position of a different character. Itโs the โnot like other charactersโ search, and itโs looking backward.
- 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
std::size().
๐ find_last_not_of โ C substring 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 [noexcept]
Find last position of a character not in C substring. Backward search, C-style string, and a limit on how many characters from s weโre considering. Very exact. Very mindful of boundaries.
- 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
std::size().
๐ find_last_not_of โ C string 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], [noexcept]
Find last position of a character not in C string. The whole C string is invited to the โcharacters to avoidโ party.
- 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.
- References
std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of().
๐ง find_last_not_of โ string_view-ish edition
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, size_type > std::basic_string<
_CharT, _Traits, _Alloc >::find_last_not_of (const _Tp & __svt,
size_type __pos = npos) const [inline], [noexcept]
Find last position of a character not in a string_view. Convertible-to-string_view object? Accepted. Searching backward? Obviously.
- Parameters
__svtโ An object convertible tostring_viewcontaining characters to avoid.__posโ Index of character to search back from (default end).
- Returns โ Index of last occurrence.
- References
std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of().
๐ find_last_not_of โ string edition
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. The avoid-list is another basic_string, and weโre going backward like weโre scrolling to the beginning of the timeline.
- Parameters
__strโ String containing characters to avoid.__posโ Index of character to search back from (default end).
- Returns โ Index of last occurrence.
Starting from __pos, searches backward for a character not contained in __str within this string. If found, returns the index where it was found. If not found, returns npos.
- References
std::basic_string< _CharT, _Traits, _Alloc >::data(),std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(), andstd::basic_string< _CharT, _Traits, _Alloc >::size(). - Referenced by
std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(),std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(), andstd::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of().
๐ 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], [noexcept]
Find last position of a character. One character. Last appearance. Scrolling backward with intention.
- Parameters
__cโ Character to locate.__posโ Index of character to search back from (default end).
- Returns โ Index of last occurrence.
Starting from __pos, searches backward for __c within this string. If found, returns the index where it was found. If not found, returns npos.
Note: equivalent to rfind(__c, __pos).
- References
std::basic_string< _CharT, _Traits, _Alloc >::rfind().
โญ find_last_of โ C substring edition
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 [noexcept]
Find last position of a character of C substring. Youโve got a C string, a starting point, and a count of characters from s to search for. The group chat is limited, but the search is still real.
- Parameters
__sโ C string containing characters to locate.__posโ Index of character to search back from.__nโ Number of characters fromsto search for.
- Returns โ Index of last occurrence.
Starting from __pos, searches backward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
- References
std::size().
๐ find_last_of โ C string edition
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. Whole C string, last matching character, no count needed. We love a simple ask.
- Parameters
__sโ C string containing characters to locate.__posโ Index of character to search back from (default end).
- Returns โ Index of last occurrence.
Starting from __pos, searches backward for one of the characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.
- References
std::basic_string< _CharT, _Traits, _Alloc >::find_last_of().
๐ find_last_of โ string_view-ish edition
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, size_type > std::basic_string<
_CharT, _Traits, _Alloc >::find_last_of (const _Tp & __svt, size_type
__pos = npos) const [inline], [noexcept]
Find last position of a character of string.
Parameters
__svtโ an object that converts tostring_view, holding the characters you're hunting for ๐ต๏ธโโ๏ธ__posโ the index of the character to search back from (defaults to the end, bestie)
Returns
The index of the last occurrence ๐
References std::basic_string< _CharT, _Traits, _Alloc >::find_last_of().
find_last_of โ the basic_string flavor ๐
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]
Okay so this one literally finds the last position of any character from a string, no cap.
Parameters
__strโ the string containing the characters to locate__posโ the index of the character to search back from (default is the end)
Returns
The index of the last occurrence โจ
So here's the vibe: starting from __pos, it searches backward for one of the characters of __str inside this string. If it finds one, it hands you the index where it was found. If it doesn't? npos. That's it, that's the whole story ๐ญ
References std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::find_last_of(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
Also referenced by std::basic_string< _CharT, _Traits, _Alloc >::find_last_of(), std::basic_string< _CharT, _Traits, _Alloc >::find_last_of(), and std::basic_string< _CharT, _Traits, _Alloc >::find_last_of(). (Yes, she references herself. Main character energy, honestly ๐)
front โ read/write edition ๐ธ
template<typename _CharT , typename _Traits , typename _Alloc > reference
std::basic_string< _CharT, _Traits, _Alloc >::front () [inline]
Gives you a read/write reference to the data sitting at the very first element of the string. First one up, front of the line, main character of the string ๐
References std::basic_string< _CharT, _Traits, _Alloc >::empty(), and std::basic_string< _CharT, _Traits, _Alloc >::operator[]().
front โ const edition ๐ฆ
template<typename _CharT , typename _Traits , typename _Alloc >
const_reference std::basic_string< _CharT, _Traits, _Alloc >::front ()
const [inline], [noexcept]
Same first element, but read-only. Look, don't touch ๐ She's giving constant reference, literally.
References std::basic_string< _CharT, _Traits, _Alloc >::empty(), and std::basic_string< _CharT, _Traits, _Alloc >::operator[]().
get_allocator ๐ง
template<typename _CharT , typename _Traits , typename _Alloc >
allocator_type std::basic_string< _CharT, _Traits, _Alloc
>::get_allocator () const [inline], [noexcept]
Returns a copy of the allocator that was used to construct this string. Like, the receipts of who built this thing ๐
Referenced by std::basic_string< _CharT, _Traits, _Alloc >::~basic_string(), std::basic_string< _CharT, _Traits, _Alloc >::assign(), std::basic_string< _CharT, _Traits, _Alloc >::clear(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::str().
โจ the insert era โจ (yes there are SO many, buckle up)
insert โ one single character ๐
template<typename _CharT , typename _Traits , typename _Alloc > iterator
std::basic_string< _CharT, _Traits, _Alloc >::insert (iterator __p,
_CharT __c) [inline]
Insert one character. One. Singular. Iconic.
Parameters
__pโ an iterator referencing the position in the string to insert at__cโ the character to insert
Returns
An 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 makes the length exceed max_size(), length_error gets thrown. If __p is beyond the end of the string, out_of_range gets thrown. And the string's value doesn't change if an error is thrown โ no half-finished chaos, we love a clean rollback ๐
insert โ a whole range of characters ๐
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, not just one ๐
Parameters
__pโ an iterator referencing the location in the string to insert at__begโ start of the range__endโ end of the range
Exceptions
std::length_errorโ if the new length exceedsmax_size()
Inserts the characters in the range [__beg,__end). If adding those characters makes the length exceed max_size(), length_error gets thrown. The value of the string doesn't change if an error is thrown. Periodt.
References std::basic_string< _CharT, _Traits, _Alloc >::replace().
insert โ an initializer_list ๐
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. Very curly-braces of her โจ
Parameters
__pโ an iterator referencing the location in the string to insert at__lโ theinitializer_listof characters to insert
Exceptions
std::length_errorโ if the new length exceedsmax_size()
References std::basic_string< _CharT, _Traits, _Alloc >::insert().
insert โ multiple copies of one char, at an iterator ๐ฆ
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. Same char, __n times, we're spamming it on purpose ๐ซถ
Parameters
__pโ an iterator referencing the location in the string to insert at__nโ number of characters to insert__cโ the character to insert
Exceptions
std::length_errorโ if the new length exceedsmax_size()
Inserts __n copies of character __c starting at the position referenced by iterator __p. If adding characters makes the length exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
References std::basic_string< _CharT, _Traits, _Alloc >::replace().
Referenced by std::basic_string< _CharT, _Traits, _Alloc >::insert(), std::basic_string< _CharT, _Traits, _Alloc >::insert(), std::basic_string< _CharT, _Traits, _Alloc >::insert(), std::basic_string< _CharT, _Traits, _Alloc >::insert(), and std::basic_string< _CharT, _Traits, _Alloc >::insert(). (Five of them. FIVE. She's popular ๐)
insert โ a C string ๐ฟ
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. Retro, but it ate.
Parameters
__posโ position in the string to insert at__sโ the C string to insert
Returns
A reference to this string ๐
Exceptions
std::length_errorโ if the 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 makes the length 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.
References std::basic_string< _CharT, _Traits, _Alloc >::insert().
insert โ a C substring ๐ธ
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)
Insert a C substring โ now with a length limit, because we're being responsible ๐
Parameters
__posโ position in the string to insert at__sโ the C string to insert__nโ the number of characters to insert
Returns
A reference to this string ๐
Exceptions
std::length_errorโ if the 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 makes the length exceed max_size(), length_error is thrown. If __pos is beyond end(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.
insert โ a string_view convertible situation ๐ง
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string<
_CharT, _Traits, _Alloc >::insert (size_type __pos, const _Tp & __svt)
[inline]
Insert a string_view. Modern. Chic. Obsessed.
Parameters
__posโ position in the string to insert at__svtโ the object convertible tostring_viewto insert
Returns
A reference to this string ๐
References std::basic_string< _CharT, _Traits, _Alloc >::insert().
insert โ multiple chars at an index ๐ฅ
template<typename _CharT , typename _Traits , typename _Alloc > basic_string
& std::basic_string< _CharT, _Traits, _Alloc >::insert (size_type __pos,
size_type __n, _CharT __c) [inline]
Insert multiple characters. Same energy as before, but indexed instead of iterator'd ๐
Parameters
__posโ index in the string to insert at__nโ number of characters to insert__cโ the character to insert
Returns
A reference to this string ๐
Exceptions
std::length_errorโ if the 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 makes the length exceed max_size(), length_error is thrown. If __pos > length(), out_of_range is thrown. The value of the string doesn't change if an error is thrown.
insert โ string_view, but slice it first โ๏ธ
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string<
_CharT, _Traits, _Alloc >::insert (size_type __pos1, const _Tp & __svt,
size_type __pos2, size_type __n = npos) [inline]
Insert a string_view. But this time โ and hear me out โ we're taking a slice of the string_view first. Double positioning, double iconic ๐
Parameters
__pos1โ position in the string to insert at__svtโ the object convertible tostring_viewto insert from__pos2โ position in thestring_viewto insert from__nโ the number of characters to insert
Returns
A reference to this string ๐
References std::basic_string< _CharT, _Traits, _Alloc >::replace().
insert โ the value of a whole string ๐
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 the value of a string. String-ception, and she's serving.
Parameters
__pos1โ position in the string to insert at__strโ the string to insert
Returns
A reference to this string ๐
Exceptions
std::length_errorโ if the new length exceedsmax_size()
Inserts the value of __str starting at __pos1. If adding characters makes the length exceed max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown.
References std::basic_string< _CharT, _Traits, _Alloc >::insert(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
insert โ a substring of a string, the final boss ๐ซถ
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. Four parameters. She said "go big or go home" ๐
Parameters
__pos1โ position in the string to insert at__strโ the string to insert__pos2โ start of characters in str to insert__nโ number of characters to insert
Returns
A reference to this string ๐
Exceptions
std::length_errorโ if the new length exceedsmax_size()std::out_of_rangeโ if pos1 > size() or__pos2> str.size()
Starting at pos1, insert __n characters of __str beginning with __pos2. If adding characters makes the length exceed max_size(), length_error is thrown. If __pos1 is beyond the end of this string or __pos2 is beyond the end of __str, out_of_range is thrown. The value of the string doesn't change if an error is thrown.
ngl the "value doesn't change if an error is thrown" guarantee showing up on every single overload is lowkey the most reassuring thing in this whole page. Strong exception safety? We stan a reliable queen ๐ โจ
๐ธ length () โ how many chars tho
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 ๐ . That's the whole personality of this one.
References std::basic_string< _CharT, _Traits, _Alloc >::size().
Referenced by std::collate< _CharT >::do_compare(), std::collate< _CharT >::do_transform(), std::regex_traits< _Ch_type >::length(), and std::regex_replace().
๐ max_size () โ the ceiling, bestie
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. Like, the absolute ceiling. The final boss of lengths ๐๏ธ.
Referenced by std::getline(), and std::operator>>().
๐ฆ operator __sv_type () โ the glow-up into a string_view
template<typename _CharT , typename _Traits , typename _Alloc >
std::basic_string< _CharT, _Traits, _Alloc >::operator __sv_type () const [inline], [noexcept]
Convert to a string_view. Lowkey iconic conversion behavior โจ.
Returns
- A
string_view.
References std::basic_string< _CharT, _Traits, _Alloc >::data(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
โ operator+= (_CharT __c) โ append one lil char
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::operator+= (_CharT __c) [inline]
Append a character. Just the one. A single little guy ๐.
Parameters
__cโ The character to append.
Returns
- Reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::push_back().
โ operator+= (const _CharT * __s) โ append a C string
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::operator+= (const _CharT * __s) [inline]
Append a C string. Yes, the old-school null-terminated kind, she still serves ๐ซถ.
Parameters
__sโ The C string to append.
Returns
- Reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
โ operator+= (const _Tp & __svt) โ append a string_view
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp >
_If_sv< _Tp, basic_string & >
std::basic_string< _CharT, _Traits, _Alloc >::operator+= (const _Tp & __svt) [inline]
Append a string_view. Note the _If_sv< _Tp, basic_string & > guard โ it only kicks in when the type is actually convertible, iykyk ๐.
Parameters
__svtโ The object convertible tostring_viewto be appended.
Returns
- Reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
โ operator+= (const basic_string & __str) โ append a whole string
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::operator+= (const basic_string< _CharT, _Traits, _Alloc > & __str) [inline]
Append a string to this string. String-on-string. Grown-folk business ๐.
Parameters
__strโ The string to append.
Returns
- Reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
โ operator+= (initializer_list< _CharT > __l) โ append a brace-ful of chars
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. Very { 'a', 'b' } of it ๐
.
Parameters
__lโ Theinitializer_listof characters to be appended.
Returns
- Reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::append().
โ๏ธ operator= (_CharT __c) โ become one character
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::operator= (_CharT __c) [inline]
Set value to a string of length 1. Main character energy, literally one of her ๐ญ.
Parameters
__cโ Source character.
Assigning to a character makes this string length 1 and (*this)[0] == c.
References std::basic_string< _CharT, _Traits, _Alloc >::assign().
๐ operator= (basic_string< _CharT, _Traits, _Alloc > && __str) โ move-assign, no copies
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.
Parameters
__strโ Source string.
The contents of str are moved into this string (without copying). str is a valid, but unspecified string. So like, she's still alive and legal to touch, but don't go assuming what's in her after the move ๐.
References std::basic_string< _CharT, _Traits, _Alloc >::swap().
โ๏ธ operator= (const _CharT * __s) โ copy in a C string
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.
References std::basic_string< _CharT, _Traits, _Alloc >::assign().
โ๏ธ operator= (const _Tp & __svt) โ assign from a string_view
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp >
_If_sv< _Tp, basic_string & >
std::basic_string< _CharT, _Traits, _Alloc >::operator= (const _Tp & __svt) [inline]
Set value to a string constructed from a string_view.
Parameters
__svtโ An object convertible tostring_view.
References std::basic_string< _CharT, _Traits, _Alloc >::assign().
โ๏ธ operator= (const basic_string< _CharT, _Traits, _Alloc > & __str) โ copy-assign
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.
References std::basic_string< _CharT, _Traits, _Alloc >::assign().
โ๏ธ operator= (initializer_list< _CharT > __l) โ assign from a brace list
template<typename _CharT , typename _Traits , typename _Alloc >
basic_string &
std::basic_string< _CharT, _Traits, _Alloc >::operator= (initializer_list< _CharT > __l) [inline]
Set value to a string constructed from an initializer list.
Parameters
__lโstd::initializer_list.
References std::basic_string< _CharT, _Traits, _Alloc >::assign().
๐ operator[] (size_type __pos) โ the read/write subscript
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. Array-style, iconic, timeless ๐.
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().) Unshares the string.
โ ๏ธ Okay bestie, read this twice: unchecked. Out-of-range is undefined behavior, not a cute little exception. If you're not 100% sure__posis valid, useat()and stop playing with fire ๐๐ฅ
References std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ operator[] (size_type __pos) const โ the read-only subscript
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, but make it const โจ.
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().)
โ ๏ธ Same warning, same drama โ unchecked and undefined out-of-range behavior. The const version doesn't unshare the string, but it will absolutely not save you from a bad index ๐
References std::basic_string< _CharT, _Traits, _Alloc >::size().
Referenced by std::basic_string< _CharT, _Traits, _Alloc >::back(), std::basic_string< _CharT, _Traits, _Alloc >::back(), std::basic_string< _CharT, _Traits, _Alloc >::front(), and std::basic_string< _CharT, _Traits, _Alloc >::front().
๐๏ธ pop_back () โ bye-bye last char
template<typename _CharT , typename _Traits , typename _Alloc >
void
std::basic_string< _CharT, _Traits, _Alloc >::pop_back () [inline]
Remove the last character. The string must be non-empty. Like, she can't lose a char she doesn't have, so vibe-check with empty() first ๐ญ.
References std::basic_string< _CharT, _Traits, _Alloc >::empty(), std::basic_string< _CharT, _Traits, _Alloc >::erase(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ฅ push_back (_CharT __c) โ bestie incoming
template<typename _CharT , typename _Traits , typename _Alloc >
void
std::basic_string< _CharT, _Traits, _Alloc >::push_back (_CharT __c) [inline]
Append a single character. One char, one queen, one addition to the roster ๐.
Parameters
__cโ Character to append.
References std::basic_string< _CharT, _Traits, _Alloc >::capacity(), std::basic_string< _CharT, _Traits, _Alloc >::reserve(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
Referenced by std::collate< _CharT >::do_transform(), std::basic_string< _CharT, _Traits, _Alloc >::operator+=(), std::tr2::operator>>(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow().
โช rbegin () โ reverse iterator, read/write
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 she starts at the end and walks backward, which is honestly so her ๐ . Unshares the string.
References std::basic_string< _CharT, _Traits, _Alloc >::end().
โช rbegin () const โ reverse iterator, read-only
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.
References std::basic_string< _CharT, _Traits, _Alloc >::end().
โฉ rend () โ reverse end, read/write
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. Unshares the string.
References std::basic_string< _CharT, _Traits, _Alloc >::begin().
โฉ rend () const โ reverse end, read-only
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.
References std::basic_string< _CharT, _Traits, _Alloc >::begin().
๐ replace (const_iterator __i1, const_iterator __i2, const _Tp & __svt) โ swap a range for a string_view
template<typename _CharT , typename _Traits , typename _Alloc >
template<typename _Tp >
_If_sv< _Tp, basic_string & >
std::basic_string< _CharT, _Traits, _Alloc >::replace (const_iterator __i1, const_iterator __i2, const _Tp & __svt) [inline]
Replace a range of characters with a string_view. Out with the old, in with the view โจ.
Parameters
__i1โ An iterator referencing the start position to replace at.__i2โ An iterator referencing the end position for the replace.__svtโ The object convertible tostring_viewto insert from.
Returns
- Reference to this string.
References std::basic_string< _CharT, _Traits, _Alloc >::begin(), and std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐ replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2) โ swap a range for a range
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 a range of characters with a range. Two iterator pairs, one glow-up ๐ฆ.
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().
๐ Heads up: blow pastmax_size()and she throwsstd::length_error. Respect the ceiling, fr fr.
...okay so picking up right where we left off: it removes the characters in the range [__i1,__i2), and in place of them, the characters in the range [__k1,__k2) get inserted. โจ If the length of the result exceeds max_size(), length_error is thrown. And the bestie-safe part? The value of the string doesn't change if an error is thrown. ๐ซถ
๐
replace() โ replace a range with a C string
template<typename _CharT , typename _Traits , typename _Alloc > basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1, iterator __i2, const _CharT * __s) [inline]
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. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐ฆ replace() โ replace a range with a C substring
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โ 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. ๐ธ
References: std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐ replace() โ replace a range with a whole other string
template<typename _CharT , typename _Traits , typename _Alloc > basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1, iterator __i2, const basic_string< _CharT, _Traits, _Alloc > & __str) [inline]
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. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::replace(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
๐ replace() โ replace a range with an initializer_list
template<typename _CharT , typename _Traits , typename _Alloc > basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l) [inline]
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. ๐
References: std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐ replace() โ replace a range with n copies of a char
template<typename _CharT , typename _Traits , typename _Alloc > basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace (iterator __i1, iterator __i2, size_type __n, _CharT __c) [inline]
Replace range of characters with multiple characters. ๐ญ (in a good way)
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() โ replace a range with a string_view-ish thing
template<typename _CharT , typename _Traits , typename _Alloc > template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos, size_type __n, const _Tp & __svt) [inline]
Replace range of characters with string_view. ๐ฆ
Parameters
__posโ The position to replace at.__nโ The number of characters to replace.__svtโ The object convertible tostring_viewto insert.
Returns
Reference to this string.
References: std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐ replace() โ replace characters with the value of another string
template<typename _CharT , typename _Traits , typename _Alloc > basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos, size_type __n, const basic_string< _CharT, _Traits, _Alloc > & __str) [inline]
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โ Ifposis 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. ๐ฅ
References: std::basic_string< _CharT, _Traits, _Alloc >::replace(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
Referenced by โ and bestie, the repeats are not a typo, there are genuinely that many overloads fr fr ๐:
std::basic_string< _CharT, _Traits, _Alloc >::append()std::basic_string< _CharT, _Traits, _Alloc >::assign()std::basic_string< _CharT, _Traits, _Alloc >::insert()std::basic_string< _CharT, _Traits, _Alloc >::insert()std::basic_string< _CharT, _Traits, _Alloc >::insert()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()
๐ replace() โ replace characters with the value of a C string
template<typename _CharT , typename _Traits , typename _Alloc > basic_string & std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos, size_type __n1, const _CharT * __s) [inline]
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. ๐ซ
References: std::basic_string< _CharT, _Traits, _Alloc >::replace().
โญ replace() โ replace characters with the value of a C substring
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)
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 fromsto 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() โ replace characters with multiple characters
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() โ replace a range with a slice of a string_view-ish thing
template<typename _CharT , typename _Traits , typename _Alloc > template<typename _Tp > _If_sv< _Tp, basic_string & > std::basic_string< _CharT, _Traits, _Alloc >::replace (size_type __pos1, size_type __n1, const _Tp & __svt, size_type __pos2, size_type __n2 = npos) [inline]
Replace range of characters with string_view. ๐
Parameters
__pos1โ The position to replace at.__n1โ The number of characters to replace.__svtโ The object convertible tostring_viewto insert from.__pos2โ The position in thestring_viewto insert from.__n2โ The number of characters to insert. (defaults tonpos, iykyk โจ)
Returns
Reference to this string.
References: std::basic_string< _CharT, _Traits, _Alloc >::replace().
โจ replace โ the "swap in someone else's glow" move ๐
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]
Okay so this overload is the five-parameter replace serve, and it is lowkey surgical, bestie. It swaps a chunk of this string for a chunk of another string. No cap.
Parameters:
__pos1โ index of first character to replace. Like the start of the makeover zone.__n1โ number of characters to be replaced. How many are getting evicted.__strโ string to insert. The incoming icon.__pos2โ index of first character ofstrto use. Where we start copying from__str.__n2โ number of characters fromstrto use.
Returns: Reference to this string. Chaining rights? periodt.
Exceptions:
std::out_of_rangeโ if__pos1 > size()or__pos2 > __str.size().std::length_errorโ if new length exceedsmax_size().
It 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. Safety behavior! We love a no-corruption moment.
References: std::basic_string< _CharT, _Traits, _Alloc >::replace().
๐ธ reserve() โ the no-arg version, yes really ๐
template<typename _CharT , typename _Traits , typename _Alloc > void std::basic_string< _CharT, _Traits, _Alloc >::reserve ()
Equivalent to shrink_to_fit(). That's it. Tiny function, big "okay werk" energy. โจ
Referenced by: std::basic_string< _CharT, _Traits, _Alloc >::push_back(), and std::basic_string< _CharT, _Traits, _Alloc >::shrink_to_fit().
๐ฆ reserve(size_type __res_arg) โ preallocating the vibe โจ
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. We stan planning ahead, honestly.
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. Prevent reallocation. Prevent copying. Main character optimization energy.
References: std::size().
Referenced by: std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::num_get< _CharT, _InIter >::do_get(), std::tr2::operator>>(), and std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow().
๐ resize(size_type __n) โ truncate or extend, no drama ๐
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. Default-constructed chars are just lil zeroes, iykyk.
References: std::basic_string< _CharT, _Traits, _Alloc >::resize().
๐ resize(size_type __n, _CharT __c) โ extend with your fave char ๐ธ
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. Fill char? Iconic behavior.
References: std::size().
Referenced by: std::money_get< _CharT, _InIter >::do_get(), and std::basic_string< _CharT, _Traits, _Alloc >::resize().
๐ฅ rfind(_CharT __c, size_type __pos = npos) โ searching backward, main character energy ๐
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 [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. Backward search? She's looking back, but make it fashion.
References: std::size().
๐ rfind(const _CharT * __s, size_type __pos, size_type __n) โ last C substring moment ๐
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 [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. First __n chars only. We're being specific.
References: std::min(), and std::size().
๐ rfind(const _CharT * __s, size_type __pos = npos) โ C string, last call ๐ฆ
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. If not found? npos. The eternal "no bestie" answer.
References: std::basic_string< _CharT, _Traits, _Alloc >::rfind().
๐ง rfind(const _Tp & __svt, size_type __pos = npos) โ string_view edition ๐
template<typename _CharT , typename _Traits , typename _Alloc > template<typename _Tp > _If_sv< _Tp, size_type > std::basic_string< _CharT, _Traits, _Alloc >::rfind (const _Tp & __svt, size_type __pos = npos) const [inline], [noexcept]
Find last position of a string_view.
Parameters:
__svtโ the object convertible to string_view to locate.__posโ index of character to search back from (default end).
Returns: Index of start of last occurrence.
References: std::basic_string< _CharT, _Traits, _Alloc >::rfind().
๐ rfind(const basic_string& __str, size_type __pos = npos) โ last position of a string ๐
template<typename _CharT , typename _Traits , typename _Alloc > size_type std::basic_string< _CharT, _Traits, _Alloc >::rfind (const basic_string< _CharT, _Traits, _Alloc > & __str, size_type __pos = npos) const [inline], [noexcept]
Find last position of a string.
Parameters:
__strโ string to locate.__posโ index of character to search back from (default end).
Returns: Index of start of last occurrence.
Starting from __pos, searches backward for value of __str within this string. If found, returns the index where it begins. If not found, returns npos.
References: std::basic_string< _CharT, _Traits, _Alloc >::data(), std::basic_string< _CharT, _Traits, _Alloc >::rfind(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
Referenced by:
std::basic_string< _CharT, _Traits, _Alloc >::find_last_of()std::basic_string< _CharT, _Traits, _Alloc >::rfind()std::basic_string< _CharT, _Traits, _Alloc >::rfind()std::basic_string< _CharT, _Traits, _Alloc >::rfind()
๐ shrink_to_fit() โ non-binding capacity request, no pressure ๐ซถ
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(). Non-binding means it's a vibe request, not a demand. She may or may not listen.
References: std::basic_string< _CharT, _Traits, _Alloc >::reserve().
๐
size() โ how many chars, no null terminator ๐
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. Not including the null. She's not counting the invisible girl.
Referenced by:
std::tr2::dynamic_bitset< _WordT, _Alloc >::dynamic_bitset()std::basic_string< _CharT, _Traits, _Alloc >::append()std::basic_regex< _Ch_type, _Rx_traits >::assign()std::basic_string< _CharT, _Traits, _Alloc >::assign()std::basic_string< _CharT, _Traits, _Alloc >::at()std::basic_string< _CharT, _Traits, _Alloc >::at()std::basic_string< _CharT, _Traits, _Alloc >::back()std::basic_string< _CharT, _Traits, _Alloc >::back()std::basic_string< _CharT, _Traits, _Alloc >::cend()std::basic_string< _CharT, _Traits, _Alloc >::compare()std::basic_string< _CharT, _Traits, _Alloc >::compare()std::basic_string< _CharT, _Traits, _Alloc >::compare()std::basic_string< _CharT, _Traits, _Alloc >::compare()std::basic_string< _CharT, _Traits, _Alloc >::empty()std::basic_string< _CharT, _Traits, _Alloc >::end()std::basic_string< _CharT, _Traits, _Alloc >::end()std::basic_string< _CharT, _Traits, _Alloc >::find()std::basic_string< _CharT, _Traits, _Alloc >::find_first_not_of()std::basic_string< _CharT, _Traits, _Alloc >::find_first_of()std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of()std::basic_string< _CharT, _Traits, _Alloc >::find_last_of()std::match_results< _Bi_iter, _Alloc >::format()std::basic_string< _CharT, _Traits, _Alloc >::insert()std::basic_string< _CharT, _Traits, _Alloc >::length()std::basic_string< _CharT, _Traits, _Alloc >::operator __sv_type()std::tr2::operator>>()std::basic_string< _CharT, _Traits, _Alloc >::operator[]()std::basic_string< _CharT, _Traits, _Alloc >::operator[]()std::basic_string< _CharT, _Traits, _Alloc >::pop_back()std::basic_string< _CharT, _Traits, _Alloc >::push_back()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::replace()std::basic_string< _CharT, _Traits, _Alloc >::rfind()std::basic_stringbuf< _CharT, _Traits, _Alloc >::str()std::regex_traits< _Ch_type >::transform()
๐ธ substr(size_type __pos = 0, size_type __n = npos) โ get a substring, bestie ๐ฆ
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. Clone it. Cut it. Serve it.
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. Beyond the end? Absolutely not. out_of_range says no.
References: std::basic_string< _CharT, _Traits, _Alloc >::basic_string().
๐ซถ swap(basic_string& __s) โ swap contents with another string ๐
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.
okay so this next bit is literally the swap glow-up: it exchanges the contents of this string with that of __s in constant time ๐
โจ โ one lilโ handoff, no big-O drama. and bestie, it shows up in the receipts for std::basic_string< _CharT, _Traits, _Alloc >::assign(), and std::basic_string< _CharT, _Traits, _Alloc >::operator=() (iykyk, those two keep calling it).
Member Data Documentation ๐
hereโs the icon itself, copied exactly so nobody comes for me:
template<typename _CharT , typename _Traits , typename _Alloc > const
basic_string< _CharT, _Traits, _Alloc >::size_type std::basic_string<
_CharT, _Traits , _Alloc >::npos [static]
thatโs std::basic_string< _CharT, _Traits, _Alloc >::npos with the [static] badge ๐, and its whole personality is: the value returned by various member functions when they fail ๐ญ๐. like, when a member function flops, this is the lilโ value it hands back โ no cap, thatโs the documented behavior.
Author โจ
generated automatically by Doxygen for libstdc++ from the source code. so yes, the docs are giving auto-generated main character energy โ Doxygen pulled it straight from the libstdc++ source code, periodt ๐ซถ.
and thatโs the whole page, bestie โ the footerโs got the libstdc++ version/date stamp on it, so peek at that generated footer for the exact source/version/date tea ๐๐
๐ฆ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms