STD::WSTRING(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_cxx normal_iterator situation
  • typedef _CharT_alloc_traits::const_pointer const_pointer โ€” const pointer, straight from _CharT_alloc_traits
  • typedef const value_type & const_reference โ€” a const reference to a value_type
  • typedef 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_traits
  • typedef __gnu_cxx::__normal_iterator< pointer, basic_string > iterator โ€” the regular iterator, same normal_iterator vibe
  • typedef _CharT_alloc_traits::pointer pointer โ€” pointer, also from _CharT_alloc_traits
  • typedef value_type & reference โ€” a plain reference to a value_type
  • typedef std::reverse_iterator< iterator > reverse_iterator โ€” reverse iterator, un-const edition
  • typedef _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, as traits_type
  • typedef _Traits::char_type value_type โ€” and the actual character type lives at _Traits::char_type, which is value_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 array
  • template<typename _Tp , typename = _If_sv<_Tp, void>> basic_string (const _Tp &__t, const _Alloc &__a=_Alloc()) โ€” constructs the string from a string_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 a string_view
  • basic_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 substring
  • basic_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 too
  • basic_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 of resize_and_overwrite for 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 characters
  • basic_string & append (const _CharT *__s) โ€” append a C string
  • basic_string & append (const _CharT *__s, size_type __n) โ€” append a C substring
  • template<typename _Tp > _If_sv< _Tp, basic_string & > append (const _Tp &__svt) โ€” append a string_view ๐Ÿฆ‹
  • template<typename _Tp > _If_sv< _Tp, basic_string & > append (const _Tp &__svt, size_type __pos, size_type __n=npos) โ€” append a range of characters from a string_view
  • basic_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 substring
  • basic_string & append (initializer_list< _CharT > __l) โ€” append an initializer_list of 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 characters
  • basic_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 that noexcept clause ๐Ÿ‘€
  • basic_string & assign (const _CharT *__s) โ€” set the value to the contents of a C string
  • basic_string & assign (const _CharT *__s, size_type __n) โ€” set the value to a C substring
  • template<typename _Tp > _If_sv< _Tp, basic_string & > assign (const _Tp &__svt) โ€” set the value from a string_view
  • template<typename _Tp > _If_sv< _Tp, basic_string & > assign (const _Tp &__svt, size_type __pos, size_type __n=npos) โ€” set the value from a range of characters in a string_view
  • basic_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 string
  • basic_string & assign (initializer_list< _CharT > __l) โ€” set the value to an initializer_list of characters
  • basic_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 edition
  • reference back () โ€” no blurb in the original, just the back element doing her thing
  • const_reference back () const noexcept โ€” same, but const and noexcept
  • iterator begin () โ€” the beginning iterator, no blurb needed, she's self-explanatory
  • const_iterator begin () const noexcept โ€” const begin, noexcept, slaying quietly
  • const _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 capacity
  • const_iterator cbegin () const noexcept โ€” const begin again but with a c, iykyk
  • const_iterator cend () const noexcept โ€” the matching c-end
  • void 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 string
  • template<typename _Tp > _If_sv< _Tp, int > compare (const _Tp &__svt) const noexcept(is_same< _Tp, __sv_type >::value) โ€” compare to a string_view
  • int 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 a string_view
  • int compare (size_type __pos, size_type __n, const basic_string &__str) const โ€” compare a substring to a string
  • int compare (size_type __pos, size_type __n1, const _CharT *__s) const โ€” compare a substring to a C string
  • int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const โ€” compare a substring against a character array
  • template<typename _Tp > _If_sv< _Tp, int > compare (size_type __pos1, size_type __n1, const _Tp &__svt, size_type __pos2, size_type __n2=npos) const noexcept(is_same< _Tp, __sv_type >::value) โ€” compare to a string_view
  • int 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 string
  • const_reverse_iterator crbegin () const noexcept โ€” no blurb in the original, reverse const begin, she's backwards and proud
  • const_reverse_iterator crend () const noexcept โ€” matching reverse const end
  • const _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 empty
  • iterator end () โ€” the end iterator, also self-explanatory
  • const_iterator end () const noexcept โ€” const end, noexcept
  • bool ends_with (_CharT __x) const noexcept โ€” no blurb in the original, but yes she checks the ending
  • bool ends_with (basic_string_view< _CharT, _Traits > __x) const noexcept โ€” same check, string_view flavor
  • bool 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 characters
  • iterator erase (iterator __position) โ€” remove one character
  • basic_string & erase (size_type __pos=0, size_type __n=npos) โ€” remove characters
  • size_type find (_CharT __c, size_type __pos=0) const noexcept โ€” find the position of a character
  • size_type find (const _CharT *__s, size_type __pos, size_type __n) const noexcept โ€” find the position of a C substring
  • size_type find (const _CharT *__s, size_type __pos=0) const noexcept โ€” find the position of a C string
  • template<typename _Tp > _If_sv< _Tp, size_type > find (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value) โ€” find the position of a string_view
  • size_type find (const basic_string &__str, size_type __pos=0) const noexcept โ€” find the position of a string
  • size_type find_first_not_of (_CharT __c, size_type __pos=0) const noexcept โ€” find the position of a different character
  • size_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 substring
  • size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const noexcept โ€” find the position of a character not in a C string
  • template<typename _Tp > _If_sv< _Tp, size_type > find_first_not_of (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value) โ€” find the position of a character not in a string_view
  • size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexcept โ€” find the position of a character not in a string
  • size_type find_first_of (_CharT __c, size_type __pos=0) const noexcept โ€” find the position of a character
  • size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const noexcept โ€” find the position of a character of a C substring
  • size_type find_first_of (const _CharT *__s, size_type __pos=0) const noexcept โ€” find the position of a character of a C string
  • template<typename _Tp > _If_sv< _Tp, size_type > find_first_of (const _Tp &__svt, size_type __pos=0) const noexcept(is_same< _Tp, __sv_type >::value) โ€” find the position of a character of a string_view
  • size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexcept โ€” find the position of a character of a string
  • size_type find_last_not_of (_CharT __c, size_type __pos=npos) const noexcept โ€” find the last position of a different character
  • size_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 substring
  • size_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 string
  • template<typename _Tp > _If_sv< _Tp, size_type > find_last_not_of (const _Tp &__svt, size_type __pos=npos) const noexcept(is_same< _Tp, __sv_type >::value) โ€” find the last position of a character not in a string_view
  • size_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 string
  • size_type find_last_of (_CharT __c, size_type __pos=npos) const noexcept โ€” find the last position of a character
  • size_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 actual basic_string this time) โœจ
  • reference front () โ€” no description on this one, the manpage is being mysterious ๐Ÿ™ˆ
  • const_reference front () const noexcept โ€” same entry, const flavour, 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 an initializer_list of characters, curly-brace girlies rise ๐ŸŒธ
  • void insert (iterator __p, size_type __n, _CharT __c) โ€” inserts multiple characters, one of them, __n times ๐Ÿ’œ
  • 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 a string_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 a string_view but 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 the size() of the biggest possible string, the theoretical maximum, main character energy ๐Ÿ”ฅ
  • operator __sv_type () const noexcept โ€” converts to a string_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 a string_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 an initializer_list of 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 __str into this string ๐Ÿฆ‹
  • basic_string & operator= (const _CharT *__s) โ€” copies the contents of __s into this string ๐Ÿ“‹
  • template<typename _Tp > _If_sv< _Tp, basic_string & > operator= (const _Tp &__svt) โ€” sets the value to a string constructed from a string_view ๐Ÿ’…
  • basic_string & operator= (const basic_string &__str) โ€” assigns the value of __str to 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, but const and noexcept, 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 โ€” the const twin, equally undescribed ๐Ÿซถ
  • reverse_iterator rend () โ€” also no description, living its truth ๐ŸŒˆ
  • const_reverse_iterator rend () const noexcept โ€” and its const counterpart, 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 a string_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 an initializer_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 a string_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 a string_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 to shrink_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 a string_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 reduce capacity() down to size(), 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 to char_traits<_CharT> ๐Ÿฆ‹
  • _Alloc โ€” allocator type, defaults to allocator<_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: __s must have at least __n characters, 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_list of 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 to string_view to 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 to string_view to be appended from.
  • __pos โ€” the position in the string_view to append from.
  • __n โ€” the number of characters to append from the string_view.

Returns โ€” reference to this string.

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


๐Ÿ”ฅ append(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 of str to append.
  • __n โ€” the number of characters to append.

Returns โ€” reference to this string.

Exceptions

  • std::out_of_range if __pos is not a valid index.

This function appends __n characters from __str starting at __pos to this string. If __n is is larger than the number of available characters in __str, the remainder of __str is appended. (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 โ€” the initializer_list of 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 to string_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 to string_view.
  • __pos โ€” the position in the string_view to assign from.
  • __n โ€” the number of characters to assign. Defaults to npos, 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=() ร—5
  • std::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 of str.
  • __n โ€” number of characters to use. Defaults to npos. โœจ

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 โ€” the initializer_list of 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 to string_view to 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 to string_view to 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 of s.

Returns

  • Integer < 0, 0, or > 0.

Form the substring of this string from the __n1 characters starting at __pos. Form a string from the first __n2 characters of __s. 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: s must have at least n2 characters, '\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 to string_view to compare against.
  • __pos2 โ€” a position in the string_view to 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 of str.
  • __n2 โ€” number of characters in substring of str.

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

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 from s to 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 (default 0).

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 to string_view to locate.
  • __pos โ€” index of the character to search from (default 0).

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

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

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 __s to 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 (default 0).

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 to string_view containing characters to avoid.
  • __pos โ€” index of the character to search from (default 0).

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 (default 0).
  • Returns โ€” Index of first occurrence.

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

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

๐Ÿ” 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 (default 0).
  • Returns โ€” Index of first occurrence.

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

Note: equivalent to find(__c, __pos).
  • 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 from s to search for.
  • Returns โ€” Index of first occurrence.

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

  • References 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 (default 0).
  • Returns โ€” Index of first occurrence.

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

  • 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 to string_view containing characters to locate.
    • __pos โ€” Index of character to search from (default 0).
  • 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 (default 0).
  • Returns โ€” Index of first occurrence.

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

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

๐Ÿ’… 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 from s to consider.
  • Returns โ€” Index of last occurrence.

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

  • References 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 to string_view containing 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(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
  • Referenced by std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(), std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of(), and std::basic_string< _CharT, _Traits, _Alloc >::find_last_not_of().

๐Ÿ‘‘ 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 from s to search for.
  • Returns โ€” Index of last occurrence.

Starting from __pos, searches backward for one of the first __n characters of __s within this string. If found, returns the index where it was found. If not found, returns npos.

  • 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 to string_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 exceeds max_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 exceeds max_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 โ€” the initializer_list of characters to insert

Exceptions

  • std::length_error โ€” if the new length exceeds max_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 exceeds max_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 exceeds max_size()
  • std::out_of_range โ€” if pos is beyond the end of this string

Inserts the first n characters of __s starting at __pos. If adding characters 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 exceeds max_size()
  • std::out_of_range โ€” if __pos is beyond the end of this string

Inserts the first __n characters of __s starting at __pos. If adding characters 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 to string_view to 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 exceeds max_size()
  • std::out_of_range โ€” if __pos is beyond the end of this string

Inserts __n copies of character __c starting at index __pos. If adding characters 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 to string_view to insert from
  • __pos2 โ€” position in the string_view to 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 exceeds max_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 exceeds max_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 to string_view to 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 โ€” The initializer_list of 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 to string_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 __pos is valid, use at() 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 to string_view to insert from.

Returns

  • Reference to this string.

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


๐Ÿ” replace (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 exceeds max_size().
๐Ÿ’€ Heads up: blow past max_size() and she throws std::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 exceeds max_size().

Removes the characters in the range [__i1,__i2). In place, the characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐Ÿ’€

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 from s to insert.

Returns

Reference to this string.

Exceptions

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

Removes the characters in the range [__i1,__i2). In place, the first __n characters of __s are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐ŸŒธ

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

Removes the characters in the range [__i1,__i2). In place, the value of __str is inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐ŸŽ€

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 โ€” The initializer_list of characters to insert.

Returns

Reference to this string.

Exceptions

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

Removes the characters in the range [__i1,__i2). In place, characters in the range [__k1,__k2) are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐Ÿ’…

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

Removes the characters in the range [__i1,__i2). In place, __n copies of __c are inserted. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. โœจ


๐Ÿงš replace() โ€” 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 to string_view to 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 โ€” If pos is beyond the end of this string.
  • std::length_error โ€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos+__n) from this string. In place, the value of __str is inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of the result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐Ÿ”ฅ

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 โ€” If pos > size().
  • std::length_error โ€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the characters of __s are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐Ÿ’ซ

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 from s to use.

Returns

Reference to this string.

Exceptions

  • std::out_of_range โ€” If pos1 > size().
  • std::length_error โ€” If new length exceeds max_size().

Removes the characters in the range [__pos,__pos + __n1) from this string. In place, the first __n2 characters of __s are inserted, or all of __s if __n2 is too large. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐Ÿซถ


๐Ÿ”ฅ replace() โ€” 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 exceeds max_size().

Removes the characters in the range [pos,pos + n1) from this string. In place, __n2 copies of __c are inserted. If __pos is beyond end of string, out_of_range is thrown. If the length of result exceeds max_size(), length_error is thrown. The value of the string doesn't change if an error is thrown. ๐Ÿ’€


๐Ÿงšโ€โ™€๏ธ replace() โ€” 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 to string_view to insert from.
  • __pos2 โ€” The position in the string_view to insert from.
  • __n2 โ€” The number of characters to insert. (defaults to npos, 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 of str to use. Where we start copying from __str.
  • __n2 โ€” number of characters from str to 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 exceeds max_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_arg exceeds max_size().

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

The advantage of this function is that if optimal code is a necessity and the user can determine the string length that will be required, the user can reserve the memory in advance, and thus prevent a possible reallocation of memory and copying of string data. 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