__GNU_CXX::__RC_STRING_BASE(3)
π __gnu_cxx::__rc_string_base< _CharT, _Traits, _Alloc > π
okay bestie, welcome to the libstdc++ corner of the manual β this one's a Library Functions Manual page, and it's all about a template class deep in the guts of __gnu_cxx. Buckle up π
β¨ NAME β¨
__gnu_cxx::__rc_string_base< _CharT, _Traits, _Alloc > β yes the whole thing, she's a template, she contains multitudes π
πΈ SYNOPSIS πΈ
#include <rc_string_base.h>
π¦ Inherited by
__gnu_cxx::__versa_string< char, std::char_traits< char >, std::allocator< char >, __rc_string_base >[private]__gnu_cxx::__versa_string< wchar_t, std::char_traits< wchar_t >, std::allocator< wchar_t >, __rc_string_base >[private]__gnu_cxx::__versa_string< char16_t, std::char_traits< char16_t >, std::allocator< char16_t >, __rc_string_base >[private]__gnu_cxx::__versa_string< char32_t, std::char_traits< char32_t >, std::allocator< char32_t >, __rc_string_base >[private]
like. she's the blueprint. all four of those versa_strings are her daughters and they all inherited privately. iykyk π
π Public Types
typedef _Util_Base::_CharT_alloc_type _CharT_alloc_typetypedef __vstring_utility< _CharT, _Traits, _Alloc > _Util_Basetypedef _Alloc allocator_typetypedef _CharT_alloc_type::size_type size_typetypedef _Traits traits_typetypedef _Traits::char_type value_type
π Public Member Functions
__rc_string_base (__rc_string_base &&__rcs)template<typename _InputIterator> __rc_string_base (_InputIterator __beg, _InputIterator __end, const _Alloc &__a)__rc_string_base (const __rc_string_base &__rcs)__rc_string_base (const _Alloc &__a)__rc_string_base (size_type __n, _CharT __c, const _Alloc &__a)void _M_assign (const __rc_string_base &__rcs)size_type _M_capacity () constvoid _M_clear ()bool _M_compare (const __rc_string_base &) constbool _M_compare (const __rc_string_base &__rcs) constbool _M_compare (const __rc_string_base &__rcs) const_CharT * _M_data () constvoid _M_erase (size_type __pos, size_type __n)allocator_type & _M_get_allocator ()const allocator_type & _M_get_allocator () constbool _M_is_shared () constvoid _M_leak ()size_type _M_length () constsize_type _M_max_size () constvoid _M_mutate (size_type __pos, size_type __len1, const _CharT *__s, size_type __len2)void _M_reserve (size_type __res)void _M_set_leaked ()void _M_set_length (size_type __n)void _M_swap (__rc_string_base &__rcs)template<typename _InIterator> _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, std::forward_iterator_tag)
three separate _M_compare overloads bestie, she said "one is not enough" π
π§ Protected Types
typedef __gnu_cxx::__normal_iterator< const_pointer, __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, __rc_string_base > > __const_rc_iteratortypedef __gnu_cxx::__normal_iterator< const_pointer, __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, __sso_string_base > > __const_sso_iteratortypedef __gnu_cxx::__normal_iterator< pointer, __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, __rc_string_base > > __rc_iteratortypedef __gnu_cxx::__normal_iterator< pointer, __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, __sso_string_base > > __sso_iteratortypedef __alloc_traits< _CharT_alloc_type > _CharT_alloc_traitstypedef _CharT_alloc_traits::const_pointer const_pointertypedef _CharT_alloc_type::difference_type difference_typetypedef _CharT_alloc_traits::pointer pointer
β Static Protected Member Functions
static void _S_assign (_CharT *__d, size_type __n, _CharT __c)static int _S_compare (size_type __n1, size_type __n2)static void _S_copy (_CharT *__d, const _CharT *__s, size_type __n)static void _S_copy_chars (_CharT *__p, __const_rc_iterator __k1, __const_rc_iterator __k2)static void _S_copy_chars (_CharT *__p, __const_sso_iterator __k1, __const_sso_iterator __k2)static void _S_copy_chars (_CharT *__p, __rc_iterator __k1, __rc_iterator __k2)static void _S_copy_chars (_CharT *__p, __sso_iterator __k1, __sso_iterator __k2)static void _S_copy_chars (_CharT *__p, _CharT *__k1, _CharT *__k2)template<typename _Iterator> static void _S_copy_chars (_CharT *__p, _Iterator __k1, _Iterator __k2)static void _S_copy_chars (_CharT *__p, const _CharT *__k1, const _CharT *__k2)static void _S_move (_CharT *__d, const _CharT *__s, size_type __n)
that's SEVEN _S_copy_chars overloads. seven. she said "iterator soup, eat up" π
π Detailed Description π
template<typename _CharT, typename _Traits, typename _Alloc>
class __gnu_cxx::__rc_string_base< _CharT, _Traits, _Alloc
>"Documentation? What's that? Nathan Myers ncm@cantrip.org.
not the doc quote literally being "Documentation? What's that?" β iconic behavior, no notes, periodt π
A string looks like this:
[_Rep]
_M_length
[__rc_string_base<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.
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_refdata(), and __rc_string_base::_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.
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.)
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.
All but the last paragraph is considered pretty conventional for a C++ string implementation.
one allocation, everything else is vibes and pointer math π«Ά
π Author π
Generated automatically by Doxygen for libstdc++ from the source code.
and that's the whole page bestie β¨ she's a refcounted string base class from the libstdc++ manual, and every last bit of her lives in the libstdc++ docs β go forth and template responsibly π
ππ¦
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms