__GNU_CXX::__RC_STRING_BASE(3cxx)
π NAME π
__gnu_cxx::__rc_string_base< _CharT, _Traits, _Alloc > β yes bestie, that whole glorious mouthful is the name, and this is the 3cxx libstdc++ manual page for it. It's the reference-counted string base class, and it's giving very niche-but-iconic C++ internals energy π
β¨ SYNOPSIS β¨
#include <rc_string_base.h>
Inherits: __gnu_cxx::__vstring_utility< _CharT, _Traits, _Alloc >.
π 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)
πΈ 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)
π¦ 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.
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
So _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. Slay.
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. Periodt.
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.
And ngl, all but the last paragraph is considered pretty conventional for a C++ string implementation.
π Author π
Generated automatically by Doxygen for libstdc++ from the source code.
Cute little sign-off π«Ά: source/version is libstdc++, manual 3cxx, and the footer's date slot isn't visible in this pasted copy β so no invented date from me, bestie π
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms