std::basic_string< _CharT, _Traits, _Alloc >(3) Library Functions Manual std::basic_string< _CharT, _Traits, _Alloc >(3)
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 (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) noexcept
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 () noexcept
_Alloc ())
template<typename _InputIterator > basic_string< _CharT, _Traits,
_Alloc > & _M_replace_dispatch (iterator __i1, iterator __i2, _InputIterator __k1, _InputIterator __k2, __false_type)"
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 () noexcept
const_iterator begin () const noexcept
const _CharT * c_str () const noexcept
size_type capacity () const noexcept
const_iterator cbegin () const noexcept
const_iterator cend () const noexcept
void clear () noexcept
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 noexcept
const_reverse_iterator crend () const noexcept
const _CharT * data () const noexcept
bool empty () const noexcept
iterator end () noexcept
const_iterator end () const noexcept
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 noexcept
size_type find (const _CharT *__s, size_type __pos=0) const
size_type find (_CharT __c, size_type __pos=0) const noexcept
size_type find_first_not_of (const basic_string &__str, size_type __pos=0) const noexcept
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 noexcept
size_type find_first_of (const basic_string &__str, size_type __pos=0) const noexcept
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 noexcept
size_type find_last_not_of (const basic_string &__str, size_type __pos=npos) const noexcept
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 noexcept
size_type find_last_of (const basic_string &__str, size_type __pos=npos) const noexcept
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 noexcept
reference front ()
const_reference front () const
allocator_type get_allocator () const noexcept
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 noexcept
size_type max_size () const noexcept
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 pop_back ()
void push_back (_CharT __c)
reverse_iterator rbegin () noexcept
const_reverse_iterator rbegin () const noexcept
reverse_iterator rend () noexcept
const_reverse_iterator rend () const noexcept
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 noexcept
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 noexcept
void shrink_to_fit ()
size_type size () const noexcept
basic_string substr (size_type __pos=0, size_type __n=npos) const
void swap (basic_string &__s)
Public Attributes
__pad0__: _M_dataplus(_S_empty_rep()._M_refdata()
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.
Template Parameters:
_CharT Type of character
_Traits Traits for character type, defaults to char_traits<_CharT>.
_Alloc Allocator type, defaults to allocator<_CharT>.
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 112 of file basic_string.h.
Constructor & Destructor Documentation
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.
Definition at line 178 of file basic_string.tcc.
Referenced by std::basic_string< char >::substr().
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 170 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 184 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 194 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, '