std::basic_string< _CharT, _Traits, _Alloc >(3cxx) std::basic_string< _CharT, _Traits, _Alloc >(3cxx)
NAME
std::basic_string< _CharT, _Traits, _Alloc > -
SYNOPSIS
Public Types
typedef _Alloc allocator_type
typedef
__gnu_cxx::__normal_iterator
< const_pointer, basic_string > const_iterator"
typedef
_CharT_alloc_type::const_pointer const_pointer"
typedef
_CharT_alloc_type::const_reference const_reference"
typedef std::reverse_iterator
< const_iterator > const_reverse_iterator"
typedef
_CharT_alloc_type::difference_type difference_type"
typedef
__gnu_cxx::__normal_iterator
< pointer, basic_string > iterator"
typedef _CharT_alloc_type::pointer pointer
typedef
_CharT_alloc_type::reference reference"
typedef std::reverse_iterator
< iterator > reverse_iterator"
typedef
_CharT_alloc_type::size_type size_type"
typedef _Traits traits_type
typedef _Traits::char_type value_type
Public Member Functions
basic_string ()
basic_string (const _Alloc &__a)
basic_string (const basic_string &__str)
basic_string (const basic_string &__str, size_type __pos, size_type __n=npos)
basic_string (const basic_string &__str, size_type __pos, size_type __n, const _Alloc &__a)
basic_string (const _CharT *__s, size_type __n, const _Alloc &__a=_Alloc())
basic_string (const _CharT *__s, const _Alloc &__a=_Alloc())
basic_string (size_type __n, _CharT __c, const _Alloc &__a=_Alloc())
basic_string (basic_string &&__str)
basic_string (initializer_list< _CharT > __l, const _Alloc &__a=_Alloc())
template<class _InputIterator > basic_string (_InputIterator __beg, _InputIterator __end, const _Alloc &__a=_Alloc())
~basic_string ()
template<typename _InIterator > _CharT * _S_construct (_InIterator __beg, _InIterator __end, const _Alloc &__a, forward_iterator_tag)
basic_string & append (const basic_string &__str)
basic_string & append (const basic_string &__str, size_type __pos, size_type __n)
basic_string & append (const _CharT *__s, size_type __n)
basic_string & append (const _CharT *__s)
basic_string & append (size_type __n, _CharT __c)
basic_string & append (initializer_list< _CharT > __l)
template<class _InputIterator > basic_string & append (_InputIterator __first, _InputIterator __last)
basic_string & assign (const basic_string &__str)
basic_string & assign (basic_string &&__str)
basic_string & assign (const basic_string &__str, size_type __pos, size_type __n)
basic_string & assign (const _CharT *__s, size_type __n)
basic_string & assign (const _CharT *__s)
basic_string & assign (size_type __n, _CharT __c)
template<class _InputIterator > basic_string & assign (_InputIterator __first, _InputIterator __last)
basic_string & assign (initializer_list< _CharT > __l)
const_reference at (size_type __n) const
reference at (size_type __n)
reference back ()
const_reference back () const
iterator begin ()
const_iterator begin () const
const _CharT * c_str () const
size_type capacity () const
const_iterator cbegin () const
const_iterator cend () const
void clear ()
int compare (const basic_string &__str) const
int compare (size_type __pos, size_type __n, const basic_string &__str) const
int compare (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2) const
int compare (const _CharT *__s) const
int compare (size_type __pos, size_type __n1, const _CharT *__s) const
int compare (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2) const
size_type copy (_CharT *__s, size_type __n, size_type __pos=0) const
const_reverse_iterator crbegin () const
const_reverse_iterator crend () const
const _CharT * data () const
bool empty () const
iterator end ()
const_iterator end () const
basic_string & erase (size_type __pos=0, size_type __n=npos)
iterator erase (iterator __position)
iterator erase (iterator __first, iterator __last)
size_type find (const _CharT *__s, size_type __pos, size_type __n) const
size_type find (const basic_string &__str, size_type __pos=0) const
size_type find (const _CharT *__s, size_type __pos=0) const
size_type find (_CharT __c, size_type __pos=0) const
size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const
size_type find_first_not_of (const _CharT *__s, size_type __pos, size_type __n) const
size_type find_first_not_of (const _CharT *__s, size_type __pos=0) const
size_type find_first_not_of (_CharT __c, size_type __pos=0) const
size_type find_first_of (const basic_string &__str, size_type __pos=0) const
size_type find_first_of (const _CharT *__s, size_type __pos, size_type __n) const
size_type find_first_of (const _CharT *__s, size_type __pos=0) const
size_type find_first_of (_CharT __c, size_type __pos=0) const
size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const
size_type find_last_not_of (const _CharT *__s, size_type __pos, size_type __n) const
size_type find_last_not_of (const _CharT *__s, size_type __pos=npos) const
size_type find_last_not_of (_CharT __c, size_type __pos=npos) const
size_type find_last_of (const basic_string &__str, size_type __pos=npos) const
size_type find_last_of (const _CharT *__s, size_type __pos, size_type __n) const
size_type find_last_of (const _CharT *__s, size_type __pos=npos) const
size_type find_last_of (_CharT __c, size_type __pos=npos) const
reference front ()
const_reference front () const
allocator_type get_allocator () const
void insert (iterator __p, size_type __n, _CharT __c)
template<class _InputIterator > void insert (iterator __p, _InputIterator __beg, _InputIterator __end)
void insert (iterator __p, initializer_list< _CharT > __l)
basic_string & insert (size_type __pos1, const basic_string &__str)
basic_string & insert (size_type __pos1, const basic_string &__str, size_type __pos2, size_type __n)
basic_string & insert (size_type __pos, const _CharT *__s, size_type __n)
basic_string & insert (size_type __pos, const _CharT *__s)
basic_string & insert (size_type __pos, size_type __n, _CharT __c)
iterator insert (iterator __p, _CharT __c)
size_type length () const
size_type max_size () const
basic_string & operator+= (const basic_string &__str)
basic_string & operator+= (const _CharT *__s)
basic_string & operator+= (_CharT __c)
basic_string & operator+= (initializer_list< _CharT > __l)
basic_string & operator= (const basic_string &__str)
basic_string & operator= (const _CharT *__s)
basic_string & operator= (_CharT __c)
basic_string & operator= (basic_string &&__str)
basic_string & operator= (initializer_list< _CharT > __l)
const_reference operator[] (size_type __pos) const
reference operator[] (size_type __pos)
void push_back (_CharT __c)
reverse_iterator rbegin ()
const_reverse_iterator rbegin () const
reverse_iterator rend ()
const_reverse_iterator rend () const
basic_string & replace (size_type __pos, size_type __n, const basic_string &__str)
basic_string & replace (size_type __pos1, size_type __n1, const basic_string &__str, size_type __pos2, size_type __n2)
basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s, size_type __n2)
basic_string & replace (size_type __pos, size_type __n1, const _CharT *__s)
basic_string & replace (size_type __pos, size_type __n1, size_type __n2, _CharT __c)
basic_string & replace (iterator __i1, iterator __i2, const basic_string &__str)
basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s, size_type __n)
basic_string & replace (iterator __i1, iterator __i2, const _CharT *__s)
basic_string & replace (iterator __i1, iterator __i2, size_type __n, _CharT __c)
template<class _InputIterator > basic_string & replace (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2)
basic_string & replace (iterator __i1, iterator __i2, _CharT *__k1, _CharT *__k2)
basic_string & replace (iterator __i1, iterator __i2, const _CharT *__k1, const _CharT *__k2)
basic_string & replace (iterator __i1, iterator __i2, iterator __k1, iterator __k2)
basic_string & replace (iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2)
basic_string & replace (iterator __i1, iterator __i2, initializer_list< _CharT > __l)
void reserve (size_type __res_arg=0)
void resize (size_type __n, _CharT __c)
void resize (size_type __n)
size_type rfind (const basic_string &__str, size_type __pos=npos) const
size_type rfind (const _CharT *__s, size_type __pos, size_type __n) const
size_type rfind (const _CharT *__s, size_type __pos=npos) const
size_type rfind (_CharT __c, size_type __pos=npos) const
void shrink_to_fit ()
size_type size () const
basic_string substr (size_type __pos=0, size_type __n=npos) const
void swap (basic_string &__s)
Static Public Attributes
static const size_type npos
Detailed Description
template<typename _CharT, typename _Traits, typename _Alloc>class std::basic_string< _CharT, _Traits, _Alloc >
Managing sequences of characters and character-like objects.
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.
Todo
Needs documentation! See http://gcc.gnu.org/onlinedocs/libstdc++/manual/documentation_style.html
Documentation? What's that? Nathan Myers ncm@cantrip.org.
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.
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.
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.
Definition at line 107 of file basic_string.h.
Constructor & Destructor Documentation
template<typename _CharT, typename _Traits, typename _Alloc> std::basic_string< _CharT, _Traits, _Alloc >::basic_string () [inline]
Default constructor creates an empty string.
Definition at line 432 of file basic_string.h.
Referenced by std::basic_string< char >::substr().
template<typename _CharT , typename _Traits , typename _Alloc> std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const _Alloc &__a)
[explicit]
Construct an empty string using allocator a.
Reimplemented in __gnu_debug::basic_string< _CharT, _Traits, _Allocator >.
Definition at line 180 of file basic_string.tcc.
template<typename _CharT , typename _Traits , typename _Alloc> std::basic_string< _CharT, _Traits, _Alloc >::basic_string (const basic_string<
_CharT, _Traits, _Alloc > &__str)
Construct string with copy of value of str. Parameters:
str Source string.
Definition at line 172 of file basic_string.tcc.
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 = npos)
Construct string as copy of a substring. Parameters:
str Source string.
pos Index of first character to copy from.
n Number of characters to copy (default remainder).
Definition at line 186 of file basic_string.tcc.
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 string as copy of a substring. Parameters:
str Source string.
pos Index of first character to copy from.
n Number of characters to copy.
a Allocator to use.
Definition at line 196 of file basic_string.tcc.
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())
Construct 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, '