---
name: "__gnu_cxx::__rc_string_base"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/__gnu_cxx::__rc_string_base"
---

# \_\_gnu\_cxx::\_\_rc\_string\_base(3)

## NAME

\_\_gnu\_cxx::\_\_rc\_string\_base\< \_CharT, \_Traits, \_Alloc \>

## 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\], and **\_\_gnu\_cxx::\_\_versa\_string\< char32\_t, std::char\_traits\< char32\_t \>, std::allocator\< char32\_t \>, \_\_rc\_string\_base \>** \[private\].

### Public Types

typedef \_Util\_Base::\_CharT\_alloc\_type **\_CharT\_alloc\_type**\
 typedef \_\_vstring\_utility\< \_CharT, \_Traits, \_Alloc \> **\_Util\_Base**\
 typedef \_Alloc **allocator\_type**\
 typedef \_CharT\_alloc\_type::size\_type **size\_type**\
 typedef \_Traits **traits\_type**\
 typedef \_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** () const\
 void **\_M\_clear** ()\
 bool **\_M\_compare** (const \_\_rc\_string\_base &) const\
 bool **\_M\_compare** (const \_\_rc\_string\_base &\_\_rcs) const\
 bool **\_M\_compare** (const \_\_rc\_string\_base &\_\_rcs) const\
 \_CharT \* **\_M\_data** () const\
 void **\_M\_erase** (size\_type \_\_pos, size\_type \_\_n)\
 allocator\_type & **\_M\_get\_allocator** ()\
 const allocator\_type & **\_M\_get\_allocator** () const\
 bool **\_M\_is\_shared** () const\
 void **\_M\_leak** ()\
 size\_type **\_M\_length** () const\
 size\_type **\_M\_max\_size** () const\
 void **\_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\_iterator**\
 typedef \_\_gnu\_cxx::\_\_normal\_iterator\< const\_pointer, **\_\_gnu\_cxx::\_\_versa\_string**\< \_CharT, \_Traits, \_Alloc, \_\_sso\_string\_base \> \> **\_\_const\_sso\_iterator**\
 typedef \_\_gnu\_cxx::\_\_normal\_iterator\< pointer, **\_\_gnu\_cxx::\_\_versa\_string**\< \_CharT, \_Traits, \_Alloc, \_\_rc\_string\_base \> \> **\_\_rc\_iterator**\
 typedef \_\_gnu\_cxx::\_\_normal\_iterator\< pointer, **\_\_gnu\_cxx::\_\_versa\_string**\< \_CharT, \_Traits, \_Alloc, \_\_sso\_string\_base \> \> **\_\_sso\_iterator**\
 typedef **\_\_alloc\_traits**\< \_CharT\_alloc\_type \> **\_CharT\_alloc\_traits**\
 typedef \_CharT\_alloc\_traits::const\_pointer **const\_pointer**\
 typedef \_CharT\_alloc\_type::difference\_type **difference\_type**\
 typedef \_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
```

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.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
