<ul>
<li><a href="17_intro/COPYING">License</a>
- GPL v2 license terms
- <li><a href="abi.txt">ABI Policy and Guidelines</a>
+ <li><a href="abi.txt">ABI Policy and Guidelines</a>
<li><a href="17_intro/BUGS">BUGS</a>
<li><a href="17_intro/PROBLEMS">PROBLEMS</a>
- target-specific known issues
<br>
<h2><a name="3">Chapter-Specific Documentation</a></h2>
<p>Information, extensions, notes and advice on specific implementation
- capabilites and or liabilities broken down into chapter names based on the
+ capabilites and/or liabilities broken down into chapter names based on the
C++ standard.
</p>
- <ul>
- <li>Intro (Chapter 17)
- <ul>
- <li><a href="17_intro/howto.html#1">Header files</a>
- <li><a href="17_intro/howto.html#3">Using <foo> vs <foo.h></a>
- <li><a href="17_intro/howto.html#2">Multithreading</a>
- <li><a href="17_intro/howto.html#4">Porting</a>
- <li><a href="17_intro/howto.html#5">Implementation-specific behavior</a>
- <li><a href="17_intro/howto.html#6">Using preprocessor macros to change behavior of the library</a>
- </ul>
-
- <li>Library Support (Chapter 18)
- <ul>
- <li><a href="18_support/howto.html#1">Types</a>
- <li><a href="18_support/howto.html#2">Implementation properties</a>
- <li><a href="18_support/howto.html#3">Start and Termination</a>
- <li><a href="18_support/howto.html#4">Dynamic memory management</a>
- <li><a href="18_support/howto.html#5">RTTI, the ABI, and demangling</a>
- </ul>
-
-
- <li>Diagnostics (Chapter 19)
- <ul>
- <li><a href="19_diagnostics/howto.html#1">Adding data to exceptions</a>
- <li><a href="19_diagnostics/howto.html#2">Exception class hierarchy diagram</a>
- <li><a href="19_diagnostics/howto.html#3">Concept checkers -- new and improved!</a>
- <li><a href="19_diagnostics/howto.html#4">Verbose terminate</a>
- </ul>
-
- <li>Utilities (Chapter 20)
- <ul>
- <li><a href="20_util/howto.html#1">auto_ptr is not omnipotent</a>
- <li><a href="20_util/howto.html#1">auto_ptr inside container classes</a>
- <li><a href="20_util/howto.html#1">Functors</a>
- <li><a href="20_util/howto.html#1">Pairs</a>
- </ul>
-
-
- <li>Strings (Chapter 21)
- <ul>
- <li><a href="21_strings/howto.html#1">MFC's CString</a>
- <li><a href="21_strings/howto.html#2">A case-insensitive string class</a>
- <li><a href="21_strings/howto.html#3">Breaking a C++ string into tokens</a>
- <li><a href="21_strings/howto.html#4">Simple transformations</a>
- </ul>
-
- <li>Localization (Chapter 22)
- <ul>
- <li><a href="22_locale/howto.html#1">Class locale</a>
- <li><a href="22_locale/howto.html#2">Class codecvt</a>
- <li><a href="22_locale/howto.html#3">Class ctype</a>
- <li><a href="22_locale/howto.html#4">Class messages</a>
- <li><a href="22_locale/howto.html#5">Bjarne Stroustrup on Locales</a>
- <li><a href="22_locale/howto.html#6">Nathan Myers on Locales</a>
- <li><a href="22_locale/howto.html#7">Correct Transformations </a>
- </ul>
-
- <li>Containers (Chapter 23)
- <ul>
- <li><a href="23_containers/howto.html#1">Making code unaware of the container/array difference</a>
- <li><a href="23_containers/howto.html#2">Variable-sized bitmasks</a>
- <li><a href="23_containers/howto.html#3">Containers and multithreading</a>
- <li><a href="23_containers/howto.html#4">"Hinting" during insertion</a>
- <li><a href="23_containers/howto.html#5">Bitmasks and string arguments</a>
- <li><a href="23_containers/howto.html#6"><code>std::list::size()</code> is O(n)!</a>
- <li><a href="23_containers/howto.html#7">Space overhead management for vectors </a>
- </ul>
-
- <li>Iterators (Chapter24)
- <ul>
- <li><a href="24_iterators/howto.html#1">They aren't pointers!</a>
- <li><a href="24_iterators/howto.html#1">It ends where?</a>
- </ul>
-
- <li>Algorithms (Chapter 25)
- <ul>
- <li><a href="25_algorithms/howto.html#1">Prerequisites</a>
- <li><a href="25_algorithms/howto.html#2">Special swaps</a>
- </ul>
-
- <li>Numerics (Chapter 26)
- <ul>
- <li><a href="26_numerics/howto.html#1">Complex Number Processing</a>
- <li><a href="26_numerics/howto.html#2">Array Processing</a>
- <li><a href="26_numerics/howto.html#3">Numerical Functions</a>
- <li><a href="26_numerics/howto.html#4">C99</a>
- </ul>
-
- <li>I/O (Chapter 27)
- <ul>
- <li><a href="27_io/howto.html#1">Copying a file</a>
- <li><a href="27_io/howto.html#2">The buffering is screwing up my program!</a>
- </ul>
- <ul>
- <li><a href="27_io/howto.html#3">Binary I/O</a>
- <li><a href="27_io/howto.html#6">More on binary I/O</a>
- <li><a href="27_io/howto.html#5">Deriving a stream buffer</a>
- <li><a href="27_io/howto.html#4">What is this <sstream>/stringstreams thing?</a>
- <li><a href="27_io/howto.html#7">Pathetic performance? Ditch C.</a>
- <li><a href="27_io/howto.html#8">Threads and I/O</a>
- </ul>
-
- <li>Extensions to the Standard Library
- <ul>
- <li><a href="ext/howto.html#1">Ropes and trees and hashes, oh my!</a>
- <li><a href="ext/howto.html#2">Added members and types</a>
- <li><a href="ext/howto.html#3">Allocators (versions 3.0, 3.1, 3.2)</a>
- <li><a href="ext/howto.html#4">Allocators (version 3.3)</a>
- <li><a href="ext/howto.html#5">Compile-time checks</a>
- <li><a href="ext/howto.html#6">LWG Issues</a>
- </ul>
- </ul>
+<!--
+ The list below is automatically generated. To make changes in the text,
+ edit the appropriate HOWTO file and run "make" in this directory. In
+ those files, you may reorder entries as you like, but DO NOT change the
+ "#number"s in anchors, for they are used elsewhere and in bookmarks.
+-->
+<!-- beginlist -->
+ <ul>
+ <li>Library Introduction (Chapter 17)</li>
+ <ul>
+ <li><a href="17_intro/howto.html#2">The Standard C++ header files</a></li>
+ <li><a href="17_intro/howto.html#3">The Standard C++ library and multithreading</a></li>
+ <li><a href="17_intro/howto.html#4"><code><foo></code> vs <code><foo.h></code></a></li>
+ <li><a href="17_intro/porting-howto.html">Porting HOWTO</a></li>
+ <li><a href="17_intro/howto.html#5">Behavior specific to libstdc++-v3</a></li>
+ <li><a href="17_intro/howto.html#6">Preprocessor macros controlling the library</a></li>
+ </ul>
+
+ <li>Library Support (Chapter 18)</li>
+ <ul>
+ <li><a href="18_support/howto.html#1">Types</a></li>
+ <li><a href="18_support/howto.html#2">Implementation properties</a></li>
+ <li><a href="18_support/howto.html#3">Start and Termination</a></li>
+ <li><a href="18_support/howto.html#4">Dynamic memory management</a></li>
+ <li><a href="18_support/howto.html#5">RTTI, the ABI, and demangling</a></li>
+ </ul>
+
+ <li>Diagnostics (Chapter 19)</li>
+ <ul>
+ <li><a href="19_diagnostics/howto.html#1">Adding data to exceptions</a></li>
+ <li><a href="19_diagnostics/howto.html#2">Exception class hierarchy diagram</a></li>
+ <li><a href="19_diagnostics/howto.html#3">Concept checkers -- <strong>new and improved!</strong></a></li>
+ <li><a href="19_diagnostics/howto.html#4">Verbose <code>terminate</code></a></li>
+ </ul>
+
+ <li>General Utilities (Chapter 20)</li>
+ <ul>
+ <li><a href="20_util/howto.html#1"><code>auto_ptr</code> is not omnipotent</a></li>
+ <li><a href="20_util/howto.html#2"><code>auto_ptr</code> inside container classes</a></li>
+ <li><a href="20_util/howto.html#3">Functors</a></li>
+ <li><a href="20_util/howto.html#4">Pairs</a></li>
+ </ul>
+
+ <li>Strings (Chapter 21)</li>
+ <ul>
+ <li><a href="21_strings/howto.html#1">MFC's CString</a></li>
+ <li><a href="21_strings/howto.html#2">A case-insensitive string class</a></li>
+ <li><a href="21_strings/howto.html#3">Breaking a C++ string into tokens</a></li>
+ <li><a href="21_strings/howto.html#4">Simple transformations</a></li>
+ <li><a href="21_strings/howto.html#5">Making strings of arbitrary character types</a></li>
+ </ul>
+
+ <li>Localization (Chapter 22)</li>
+ <ul>
+ <li><a href="22_locale/howto.html#1">class locale</a></li>
+ <li><a href="22_locale/howto.html#2">class codecvt</a></li>
+ <li><a href="22_locale/howto.html#3">class ctype</a></li>
+ <li><a href="22_locale/howto.html#4">class messages</a></li>
+ <li><a href="22_locale/howto.html#5">Bjarne Stroustrup on Locales</a></li>
+ <li><a href="22_locale/howto.html#6">Nathan Myers on Locales </a></li>
+ <li><a href="22_locale/howto.html#7">Correct Transformations</a></li>
+ </ul>
+
+ <li>Containers (Chapter 23)</li>
+ <ul>
+ <li><a href="23_containers/howto.html#1">Making code unaware of the container/array difference</a></li>
+ <li><a href="23_containers/howto.html#2">Variable-sized bitmasks</a></li>
+ <li><a href="23_containers/howto.html#3">Containers and multithreading</a></li>
+ <li><a href="23_containers/howto.html#4">"Hinting" during insertion</a></li>
+ <li><a href="23_containers/howto.html#5">Bitmasks and string arguments</a></li>
+ <li><a href="23_containers/howto.html#6"><code>std::list::size()</code> is O(n)!</a></li>
+ <li><a href="23_containers/howto.html#7">Space overhead management for vectors</a></li>
+ </ul>
+
+ <li>Iterators (Chapter 24)</li>
+ <ul>
+ <li><a href="24_iterators/howto.html#1">They ain't pointers!</a></li>
+ <li><a href="24_iterators/howto.html#2">It ends <em>where?</em></a></li>
+ </ul>
+
+ <li>Algorithms (Chapter 25)</li>
+ <ul>
+ <li><a href="25_algorithms/howto.html#1">Prerequisites</a></li>
+ <li><a href="25_algorithms/howto.html#2">Special <code>swap</code>s</a></li>
+ </ul>
+
+ <li>Numerics (Chapter 26)</li>
+ <ul>
+ <li><a href="26_numerics/howto.html#1">Complex Number Processing</a></li>
+ <li><a href="26_numerics/howto.html#2">Array Processing</a></li>
+ <li><a href="26_numerics/howto.html#3">Numerical Functions</a></li>
+ <li><a href="26_numerics/howto.html#4">C99</a></li>
+ </ul>
+
+ <li>Input/Output (Chapter 27)</li>
+ <ul>
+ <li><a href="27_io/howto.html#1">Copying a file</a></li>
+ <li><a href="27_io/howto.html#2">The buffering is screwing up my program!</a></li>
+ <li><a href="27_io/howto.html#3">Binary I/O</a></li>
+ <li><a href="27_io/howto.html#5">What is this <sstream>/stringstreams thing?</a></li>
+ <li><a href="27_io/howto.html#6">Deriving a stream buffer</a></li>
+ <li><a href="27_io/howto.html#7">More on binary I/O</a></li>
+ <li><a href="27_io/howto.html#8">Pathetic performance? Ditch C.</a></li>
+ <li><a href="27_io/howto.html#9">Threads and I/O</a></li>
+ </ul>
+
+ <li>Extensions to the Standard Library</li>
+ <ul>
+ <li><a href="ext/howto.html#1">Ropes and trees and hashes, oh my!</a></li>
+ <li><a href="ext/howto.html#2">Added members and types</a></li>
+ <li><a href="ext/howto.html#3">Allocators (versions 3.0, 3.1, 3.2)</a></li>
+ <li><a href="ext/howto.html#6">Allocators (version 3.3)</a></li>
+ <li><a href="ext/howto.html#4">Compile-time checks</a></li>
+ <li><a href="ext/howto.html#5">LWG Issues</a></li>
+ </ul>
+
+ </ul>
+<!-- endlist -->
<hr />
<br>
*/
#ifndef _CPP_BITS_STRING_H
-#define _CPP_BITS_STRING_H 1
+#define _CPP_BITS_STRING_H 1
#pragma GCC system_header
namespace std
{
- // 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_state
- // _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.
-
+ /**
+ * @class basic_string basic_string.h <string>
+ * @brief Managing sequences of characters and character-like objects.
+ *
+ * @ingroup Containers
+ * @ingroup Sequences
+ *
+ * Meets the requirements of a <a href="tables.html#65">container</a>, a
+ * <a href="tables.html#66">reversible container</a>, and a
+ * <a href="tables.html#67">sequence</a>. Of the
+ * <a href="tables.html#68">optional sequence requirements</a>, only
+ * @c push_back, @c at, and array access are supported.
+ *
+ * @doctodo
+ *
+ *
+ * @if maint
+ * Documentation? What's that?
+ * Nathan Myers <ncm@cantrip.org>.
+ *
+ * A string looks like this:
+ *
+ * @code
+ * [_Rep]
+ * _M_length
+ * [basic_string<char_type>] _M_capacity
+ * _M_dataplus _M_state
+ * _M_p ----------------> unnamed array of char_type
+ * @endcode
+ *
+ * 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.
+ * @endif
+ */
// 21.3 Template class basic_string
template<typename _CharT, typename _Traits, typename _Alloc>
class basic_string
const_iterator;
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
-
+
private:
// _Rep: string representation
// Invariants:
// Types:
typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
- // (Public) Data members:
+ // (Public) Data members:
// The maximum number of individual char_type elements of an
// individual string is determined by _S_max_size. This is the
// is the maximum number of bytes the allocator can allocate.)
// If one was to divvy up the theoretical largest size string,
// with a terminating character and m _CharT elements, it'd
- // look like this:
+ // look like this:
// npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
// Solving for m:
- // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
+ // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
// In addition, this implementation quarters this ammount.
static const size_type _S_max_size;
static const _CharT _S_terminal;
size_type _M_length;
size_type _M_capacity;
_Atomic_word _M_references;
-
+
bool
_M_is_leaked() const
{ return _M_references < 0; }
{ return _M_references > 0; }
void
- _M_set_leaked()
+ _M_set_leaked()
{ _M_references = -1; }
void
- _M_set_sharable()
+ _M_set_sharable()
{ _M_references = 0; }
- _CharT*
+ _CharT*
_M_refdata() throw()
{ return reinterpret_cast<_CharT*>(this + 1); }
- _CharT&
+ _CharT&
operator[](size_t __s) throw()
{ return _M_refdata() [__s]; }
- _CharT*
+ _CharT*
_M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
- {
- return (!_M_is_leaked() && __alloc1 == __alloc2)
- ? _M_refcopy() : _M_clone(__alloc1);
+ {
+ return (!_M_is_leaked() && __alloc1 == __alloc2)
+ ? _M_refcopy() : _M_clone(__alloc1);
}
// Create & Destroy
- static _Rep*
+ static _Rep*
_S_create(size_t, const _Alloc&);
- void
+ void
_M_dispose(const _Alloc& __a)
- {
- if (__exchange_and_add(&_M_references, -1) <= 0)
- _M_destroy(__a);
+ {
+ if (__exchange_and_add(&_M_references, -1) <= 0)
+ _M_destroy(__a);
} // XXX MT
- void
+ void
_M_destroy(const _Alloc&) throw();
- _CharT*
+ _CharT*
_M_refcopy() throw()
- {
- __atomic_add(&_M_references, 1);
- return _M_refdata();
+ {
+ __atomic_add(&_M_references, 1);
+ return _M_refdata();
} // XXX MT
- _CharT*
+ _CharT*
_M_clone(const _Alloc&, size_type __res = 0);
};
// (carefully) in an empty string with one reference.
static size_type _S_empty_rep_storage[(sizeof(_Rep) + sizeof(_CharT) + sizeof(size_type) - 1)/sizeof(size_type)];
- _CharT*
- _M_data() const
+ _CharT*
+ _M_data() const
{ return _M_dataplus._M_p; }
- _CharT*
- _M_data(_CharT* __p)
+ _CharT*
+ _M_data(_CharT* __p)
{ return (_M_dataplus._M_p = __p); }
- _Rep*
+ _Rep*
_M_rep() const
{ return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
// For the internal use we have functions similar to `begin'/`end'
// but they do not call _M_leak.
- iterator
+ iterator
_M_ibegin() const { return iterator(_M_data()); }
- iterator
+ iterator
_M_iend() const { return iterator(_M_data() + this->size()); }
- void
+ void
_M_leak() // for use in begin() & non-const op[]
- {
- if (!_M_rep()->_M_is_leaked())
- _M_leak_hard();
+ {
+ if (!_M_rep()->_M_is_leaked())
+ _M_leak_hard();
}
- iterator
+ iterator
_M_check(size_type __pos) const
- {
+ {
if (__pos > this->size())
- __throw_out_of_range("basic_string::_M_check");
- return _M_ibegin() + __pos;
+ __throw_out_of_range("basic_string::_M_check");
+ return _M_ibegin() + __pos;
}
// NB: _M_fold doesn't check for a bad __pos1 value.
- iterator
+ iterator
_M_fold(size_type __pos, size_type __off) const
- {
+ {
bool __testoff = __off < this->size() - __pos;
size_type __newoff = __testoff ? __off : this->size() - __pos;
return (_M_ibegin() + __pos + __newoff);
template<class _Iterator>
static void
_S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
- {
- for (; __k1 != __k2; ++__k1, ++__p)
+ {
+ for (; __k1 != __k2; ++__k1, ++__p)
traits_type::assign(*__p, *__k1); // These types are off.
}
static void
_S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
{ _S_copy_chars(__p, __k1.base(), __k2.base()); }
-
+
static void
_S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
{ traits_type::copy(__p, __k1, __k2 - __k1); }
_S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
{ traits_type::copy(__p, __k1, __k2 - __k1); }
- void
+ void
_M_mutate(size_type __pos, size_type __len1, size_type __len2);
- void
+ void
_M_leak_hard();
- static _Rep&
+ static _Rep&
_S_empty_rep()
{ return *reinterpret_cast<_Rep*>(&_S_empty_rep_storage); }
// NB: We overload ctors in some cases instead of using default
// arguments, per 17.4.4.4 para. 2 item 2.
- inline
+ inline
basic_string();
- explicit
+ explicit
basic_string(const _Alloc& __a);
// NB: per LWG issue 42, semantics different from IS:
basic_string(_InputIterator __beg, _InputIterator __end,
const _Alloc& __a = _Alloc());
- ~basic_string()
+ ~basic_string()
{ _M_rep()->_M_dispose(this->get_allocator()); }
- basic_string&
+ basic_string&
operator=(const basic_string& __str) { return this->assign(__str); }
- basic_string&
+ basic_string&
operator=(const _CharT* __s) { return this->assign(__s); }
- basic_string&
+ basic_string&
operator=(_CharT __c) { return this->assign(1, __c); }
// Iterators:
- iterator
- begin()
- {
- _M_leak();
+ iterator
+ begin()
+ {
+ _M_leak();
return iterator(_M_data());
}
- const_iterator
- begin() const
+ const_iterator
+ begin() const
{ return const_iterator(_M_data()); }
- iterator
+ iterator
end()
{
_M_leak();
return iterator(_M_data() + this->size());
}
- const_iterator
+ const_iterator
end() const
{ return const_iterator(_M_data() + this->size()); }
- reverse_iterator
- rbegin()
+ reverse_iterator
+ rbegin()
{ return reverse_iterator(this->end()); }
- const_reverse_iterator
- rbegin() const
+ const_reverse_iterator
+ rbegin() const
{ return const_reverse_iterator(this->end()); }
- reverse_iterator
- rend()
+ reverse_iterator
+ rend()
{ return reverse_iterator(this->begin()); }
- const_reverse_iterator
- rend() const
+ const_reverse_iterator
+ rend() const
{ return const_reverse_iterator(this->begin()); }
public:
// Capacity:
- size_type
+ size_type
size() const { return _M_rep()->_M_length; }
- size_type
+ size_type
length() const { return _M_rep()->_M_length; }
- size_type
+ size_type
max_size() const { return _Rep::_S_max_size; }
- void
+ void
resize(size_type __n, _CharT __c);
- void
+ void
resize(size_type __n) { this->resize(__n, _CharT()); }
- size_type
+ size_type
capacity() const { return _M_rep()->_M_capacity; }
- void
+ void
reserve(size_type __res_arg = 0);
- void
+ void
clear() { _M_mutate(0, this->size(), 0); }
- bool
+ bool
empty() const { return this->size() == 0; }
// Element access:
- const_reference
- operator[] (size_type __pos) const
+ const_reference
+ operator[] (size_type __pos) const
{ return _M_data()[__pos]; }
- reference
- operator[](size_type __pos)
- {
- _M_leak();
- return _M_data()[__pos];
+ reference
+ operator[](size_type __pos)
+ {
+ _M_leak();
+ return _M_data()[__pos];
}
- const_reference
+ const_reference
at(size_type __n) const
{
if (__n >= this->size())
__throw_out_of_range("basic_string::at");
- return _M_data()[__n];
+ return _M_data()[__n];
}
- reference
+ reference
at(size_type __n)
{
if (__n >= size())
__throw_out_of_range("basic_string::at");
- _M_leak();
- return _M_data()[__n];
+ _M_leak();
+ return _M_data()[__n];
}
// Modifiers:
- basic_string&
+ basic_string&
operator+=(const basic_string& __str) { return this->append(__str); }
- basic_string&
+ basic_string&
operator+=(const _CharT* __s) { return this->append(__s); }
- basic_string&
+ basic_string&
operator+=(_CharT __c) { return this->append(size_type(1), __c); }
- basic_string&
+ basic_string&
append(const basic_string& __str);
- basic_string&
+ basic_string&
append(const basic_string& __str, size_type __pos, size_type __n);
- basic_string&
+ basic_string&
append(const _CharT* __s, size_type __n);
- basic_string&
+ basic_string&
append(const _CharT* __s)
{ return this->append(__s, traits_type::length(__s)); }
- basic_string&
+ basic_string&
append(size_type __n, _CharT __c);
template<class _InputIterator>
- basic_string&
+ basic_string&
append(_InputIterator __first, _InputIterator __last)
{ return this->replace(_M_iend(), _M_iend(), __first, __last); }
- void
+ void
push_back(_CharT __c)
{ this->replace(_M_iend(), _M_iend(), 1, __c); }
- basic_string&
+ basic_string&
assign(const basic_string& __str);
- basic_string&
+ basic_string&
assign(const basic_string& __str, size_type __pos, size_type __n)
{
const size_type __strsize = __str.size();
return this->assign(__str._M_data() + __pos, __newsize);
}
- basic_string&
+ basic_string&
assign(const _CharT* __s, size_type __n)
{
if (__n > this->max_size())
}
}
- basic_string&
+ basic_string&
assign(const _CharT* __s)
{ return this->assign(__s, traits_type::length(__s)); }
- basic_string&
+ basic_string&
assign(size_type __n, _CharT __c)
{ return this->replace(_M_ibegin(), _M_iend(), __n, __c); }
template<class _InputIterator>
- basic_string&
+ basic_string&
assign(_InputIterator __first, _InputIterator __last)
{ return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
- void
+ void
insert(iterator __p, size_type __n, _CharT __c)
{ this->replace(__p, __p, __n, __c); }
void insert(iterator __p, _InputIterator __beg, _InputIterator __end)
{ this->replace(__p, __p, __beg, __end); }
- basic_string&
+ basic_string&
insert(size_type __pos1, const basic_string& __str)
{ return this->insert(__pos1, __str, 0, __str.size()); }
- basic_string&
+ basic_string&
insert(size_type __pos1, const basic_string& __str,
size_type __pos2, size_type __n)
{
__throw_out_of_range("basic_string::insert");
const bool __testn = __n < __strsize - __pos2;
const size_type __newsize = __testn ? __n : __strsize - __pos2;
- return this->insert(__pos1, __str._M_data() + __pos2, __newsize);
+ return this->insert(__pos1, __str._M_data() + __pos2, __newsize);
}
- basic_string&
+ basic_string&
insert(size_type __pos, const _CharT* __s, size_type __n)
{
const size_type __size = this->size();
}
}
- basic_string&
+ basic_string&
insert(size_type __pos, const _CharT* __s)
{ return this->insert(__pos, __s, traits_type::length(__s)); }
- basic_string&
+ basic_string&
insert(size_type __pos, size_type __n, _CharT __c)
- {
- this->insert(_M_check(__pos), __n, __c);
- return *this;
+ {
+ this->insert(_M_check(__pos), __n, __c);
+ return *this;
}
- iterator
+ iterator
insert(iterator __p, _CharT __c = _CharT())
{
size_type __pos = __p - _M_ibegin();
this->insert(_M_check(__pos), size_type(1), __c);
- _M_rep()->_M_set_leaked();
- return this->_M_ibegin() + __pos;
+ _M_rep()->_M_set_leaked();
+ return this->_M_ibegin() + __pos;
}
- basic_string&
+ basic_string&
erase(size_type __pos = 0, size_type __n = npos)
- {
+ {
return this->replace(_M_check(__pos), _M_fold(__pos, __n),
- _M_data(), _M_data());
+ _M_data(), _M_data());
}
- iterator
+ iterator
erase(iterator __position)
{
size_type __i = __position - _M_ibegin();
this->replace(__position, __position + 1, _M_data(), _M_data());
- _M_rep()->_M_set_leaked();
+ _M_rep()->_M_set_leaked();
return _M_ibegin() + __i;
}
- iterator
+ iterator
erase(iterator __first, iterator __last)
{
size_type __i = __first - _M_ibegin();
return _M_ibegin() + __i;
}
- basic_string&
+ basic_string&
replace(size_type __pos, size_type __n, const basic_string& __str)
{ return this->replace(__pos, __n, __str._M_data(), __str.size()); }
- basic_string&
+ basic_string&
replace(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2);
- basic_string&
+ basic_string&
replace(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2)
- {
+ {
const size_type __size = this->size();
if (__pos > __size)
__throw_out_of_range("basic_string::replace");
typename iterator_traits<const _CharT*>::iterator_category());
}
- basic_string&
+ basic_string&
replace(size_type __pos, size_type __n1, const _CharT* __s)
{ return this->replace(__pos, __n1, __s, traits_type::length(__s)); }
- basic_string&
+ basic_string&
replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
{ return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __n2, __c); }
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2, const basic_string& __str)
{ return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2,
const _CharT* __s, size_type __n)
{ return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); }
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2, const _CharT* __s)
{ return this->replace(__i1, __i2, __s, traits_type::length(__s)); }
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2, size_type __n, _CharT __c);
template<class _InputIterator>
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2,
_InputIterator __k1, _InputIterator __k2)
{ return _M_replace(__i1, __i2, __k1, __k2,
// Specializations for the common case of pointer and iterator:
// useful to avoid the overhead of temporary buffering in _M_replace.
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
{ return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
__k1, __k2 - __k1); }
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2, const _CharT* __k1, const _CharT* __k2)
{ return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
__k1, __k2 - __k1); }
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
{ return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
__k1.base(), __k2 - __k1);
}
- basic_string&
+ basic_string&
replace(iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2)
{ return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
__k1.base(), __k2 - __k1);
private:
template<class _InputIterator>
- basic_string&
- _M_replace(iterator __i1, iterator __i2, _InputIterator __k1,
+ basic_string&
+ _M_replace(iterator __i1, iterator __i2, _InputIterator __k1,
_InputIterator __k2, input_iterator_tag);
template<class _ForwardIterator>
- basic_string&
- _M_replace_safe(iterator __i1, iterator __i2, _ForwardIterator __k1,
+ basic_string&
+ _M_replace_safe(iterator __i1, iterator __i2, _ForwardIterator __k1,
_ForwardIterator __k2);
// _S_construct_aux is used to implement the 21.3.1 para 15 which
typedef typename iterator_traits<_InIter>::iterator_category _Tag;
return _S_construct(__beg, __end, __a, _Tag());
}
-
+
template<class _InIter>
static _CharT*
_S_construct_aux(_InIter __beg, _InIter __end, const _Alloc& __a,
return _S_construct(static_cast<size_type>(__beg),
static_cast<value_type>(__end), __a);
}
-
+
template<class _InIter>
static _CharT*
_S_construct(_InIter __beg, _InIter __end, const _Alloc& __a)
static _CharT*
_S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
input_iterator_tag);
-
+
// For forward_iterators up to random_access_iterators, used for
// string::iterator, _CharT*, etc.
template<class _FwdIter>
_S_construct(_FwdIter __beg, _FwdIter __end, const _Alloc& __a,
forward_iterator_tag);
- static _CharT*
+ static _CharT*
_S_construct(size_type __req, _CharT __c, const _Alloc& __a);
public:
- size_type
+ size_type
copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
- void
+ void
swap(basic_string<_CharT, _Traits, _Alloc>& __s);
// String operations:
- const _CharT*
+ const _CharT*
c_str() const
{
// MT: This assumes concurrent writes are OK.
return _M_data();
}
- const _CharT*
+ const _CharT*
data() const { return _M_data(); }
- allocator_type
+ allocator_type
get_allocator() const { return _M_dataplus; }
- size_type
+ size_type
find(const _CharT* __s, size_type __pos, size_type __n) const;
- size_type
+ size_type
find(const basic_string& __str, size_type __pos = 0) const
{ return this->find(__str.data(), __pos, __str.size()); }
- size_type
+ size_type
find(const _CharT* __s, size_type __pos = 0) const
{ return this->find(__s, __pos, traits_type::length(__s)); }
- size_type
+ size_type
find(_CharT __c, size_type __pos = 0) const;
- size_type
+ size_type
rfind(const basic_string& __str, size_type __pos = npos) const
{ return this->rfind(__str.data(), __pos, __str.size()); }
- size_type
+ size_type
rfind(const _CharT* __s, size_type __pos, size_type __n) const;
- size_type
+ size_type
rfind(const _CharT* __s, size_type __pos = npos) const
{ return this->rfind(__s, __pos, traits_type::length(__s)); }
- size_type
+ size_type
rfind(_CharT __c, size_type __pos = npos) const;
- size_type
+ size_type
find_first_of(const basic_string& __str, size_type __pos = 0) const
{ return this->find_first_of(__str.data(), __pos, __str.size()); }
- size_type
+ size_type
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const;
- size_type
+ size_type
find_first_of(const _CharT* __s, size_type __pos = 0) const
{ return this->find_first_of(__s, __pos, traits_type::length(__s)); }
- size_type
+ size_type
find_first_of(_CharT __c, size_type __pos = 0) const
{ return this->find(__c, __pos); }
- size_type
+ size_type
find_last_of(const basic_string& __str, size_type __pos = npos) const
{ return this->find_last_of(__str.data(), __pos, __str.size()); }
- size_type
+ size_type
find_last_of(const _CharT* __s, size_type __pos, size_type __n) const;
- size_type
+ size_type
find_last_of(const _CharT* __s, size_type __pos = npos) const
{ return this->find_last_of(__s, __pos, traits_type::length(__s)); }
- size_type
+ size_type
find_last_of(_CharT __c, size_type __pos = npos) const
{ return this->rfind(__c, __pos); }
- size_type
+ size_type
find_first_not_of(const basic_string& __str, size_type __pos = 0) const
{ return this->find_first_not_of(__str.data(), __pos, __str.size()); }
- size_type
- find_first_not_of(const _CharT* __s, size_type __pos,
+ size_type
+ find_first_not_of(const _CharT* __s, size_type __pos,
size_type __n) const;
- size_type
+ size_type
find_first_not_of(const _CharT* __s, size_type __pos = 0) const
{ return this->find_first_not_of(__s, __pos, traits_type::length(__s)); }
- size_type
+ size_type
find_first_not_of(_CharT __c, size_type __pos = 0) const;
- size_type
+ size_type
find_last_not_of(const basic_string& __str, size_type __pos = npos) const
{ return this->find_last_not_of(__str.data(), __pos, __str.size()); }
- size_type
- find_last_not_of(const _CharT* __s, size_type __pos,
+ size_type
+ find_last_not_of(const _CharT* __s, size_type __pos,
size_type __n) const;
- size_type
+ size_type
find_last_not_of(const _CharT* __s, size_type __pos = npos) const
{ return this->find_last_not_of(__s, __pos, traits_type::length(__s)); }
- size_type
+ size_type
find_last_not_of(_CharT __c, size_type __pos = npos) const;
- basic_string
+ basic_string
substr(size_type __pos = 0, size_type __n = npos) const
- {
+ {
if (__pos > this->size())
__throw_out_of_range("basic_string::substr");
- return basic_string(*this, __pos, __n);
+ return basic_string(*this, __pos, __n);
}
- int
+ int
compare(const basic_string& __str) const
{
size_type __size = this->size();
size_type __osize = __str.size();
size_type __len = min(__size, __osize);
-
+
int __r = traits_type::compare(_M_data(), __str.data(), __len);
if (!__r)
__r = __size - __osize;
return __r;
}
- int
+ int
compare(size_type __pos, size_type __n, const basic_string& __str) const;
- int
+ int
compare(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2) const;
- int
+ int
compare(const _CharT* __s) const;
// _GLIBCPP_RESOLVE_LIB_DEFECTS
// 5. String::compare specification questionable
- int
+ int
compare(size_type __pos, size_type __n1, const _CharT* __s) const;
- int
- compare(size_type __pos, size_type __n1, const _CharT* __s,
+ int
+ compare(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2) const;
};