add doc: basic_string assign

This commit is contained in:
Bolero-MURAKAMI 2013-09-08 18:59:50 +09:00
parent c6a9bf338a
commit 5af5e8c300
24 changed files with 1489 additions and 44 deletions

View file

@ -0,0 +1,158 @@
.. _sprout-string-basic_string-assign:
###############################################################################
assign
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<std::size_t N2>
basic_string& assign(basic_string<T, N2, Traits> const& str);
Effects
========================================
| Equivalent to ``assign(str, 0, npos)``.
Returns
========================================
| ``*this``.
----
Interface
========================================
.. sourcecode:: c++
template<std::size_t N2>
basic_string& assign(basic_string<T, N2, Traits> const& str, size_type pos, size_type n);
Requires
========================================
| ``pos <= str.size()``.
Effects
========================================
| Determines the effective length rlen of the string to assign as the smaller of n and ``str.size() - pos`` and calls ``assign(str.data() + pos, rlen)``.
Returns
========================================
| ``*this``.
Throws
========================================
| std::out_of_range if ``pos > str.size()``.
----
Interface
========================================
.. sourcecode:: c++
basic_string& assign(value_type const* s, size_type n);
Requires
========================================
| s points to an array of at least n elements of value_type.
Effects
========================================
| Replaces the string controlled by *this with a string of length n whose elements are a copy of those pointed to by s.
Returns
========================================
| ``*this``.
Throws
========================================
| std::length_error if ``n > max_size()``.
----
Interface
========================================
.. sourcecode:: c++
basic_string& assign(value_type const* s);
Requires
========================================
| s points to an array of at least ``traits_type::length(s) + 1`` elements of value_type.
Effects
========================================
| Calls ``assign(s, traits_type::length(s))``.
Returns
========================================
| ``*this``.
----
Interface
========================================
.. sourcecode:: c++
basic_string& assign(size_type n, value_type c);
Effects
========================================
| Equivalent to ``assign(basic_string(n, c))``.
Returns
========================================
| ``*this``.
----
Interface
========================================
.. sourcecode:: c++
template<typename InputIterator>
basic_string& assign(InputIterator first, InputIterator last);
Effects
========================================
| Equivalent to ``assign(basic_string(first, last))``.
Returns
========================================
| ``*this``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/string.hpp>
#include <sprout/assert.hpp>
using namespace sprout;
auto x = string<8>("homuhomu");
SPROUT_STATIC_CONSTEXPR auto y = string<8>("madocchi");
x.assign(y);
SPROUT_ASSERT_MSG(x == y, "y is assigned to x.");
Header
========================================
| ``sprout/string/string.hpp``
| Convenience header: ``sprout/string.hpp``

View file

@ -0,0 +1,34 @@
.. _sprout-string-basic_string-clear:
###############################################################################
clear
###############################################################################
Interface
========================================
.. sourcecode:: c++
void clear() SPROUT_NOEXCEPT;
Effects
========================================
| Fill [begin,end) with value_type(), and set the 0 to length.
Examples
========================================
.. sourcecode:: c++
#include <sprout/string.hpp>
#include <sprout/assert.hpp>
using namespace sprout;
auto x = string<8>("homuhomu");
x.clear();
SPROUT_ASSERT_MSG(x.size() == 0 && x == "", "string is cleared.");
Header
========================================
| ``sprout/string/string.hpp``
| Convenience header: ``sprout/string.hpp``

View file

@ -282,7 +282,7 @@ Interface of all
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT;
void resize(size_type n, value_type c);
void resize(size_type n);
void clear();
void clear() SPROUT_NOEXCEPT;
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT;
// element access:

View file

@ -0,0 +1,37 @@
.. _sprout-string-basic_string-length:
###############################################################################
length
###############################################################################
Interface
========================================
.. sourcecode:: c++
SPROUT_CONSTEXPR size_type length() const SPROUT_NOEXCEPT;
Returns
========================================
| The number of elements contained in the string.
Examples
========================================
.. sourcecode:: c++
#include <sprout/string.hpp>
using namespace sprout;
SPROUT_STATIC_CONSTEXPR auto input = string<8>("homuhomu");
static_assert(input.length() == 8, "input size is 8.");
Complexity
========================================
| Recursive function invocations in *O(1)* (constant) depth.
Header
========================================
| ``sprout/string/string.hpp``
| Convenience header: ``sprout/string.hpp``

View file

@ -0,0 +1,50 @@
.. _sprout-string-basic_string-resize:
###############################################################################
resize
###############################################################################
Interface
========================================
.. sourcecode:: c++
void resize(size_type n, value_type c);
void resize(size_type n);
Requires
========================================
| ``n <= max_size()``.
Effects
========================================
| Alters the length of the string designated by *this as follows:
* If ``n <= size()``, the function replaces the string designated by ``*this`` with a string of length n whose elements are a copy of the initial elements of the original string designated by ``*this``.
* If ``n > size()``, the function replaces the string designated by ``*this`` with a string of length n whose first size() elements are a copy of the original string designated by ``*this``, and whose remaining elements are all initialized to c.
| Equivalent to ``resize(n, value_type())`` when there is no parameter c.
Throws
========================================
| std::length_error if ``n > max_size()``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/string.hpp>
#include <sprout/assert.hpp>
using namespace sprout;
auto x = string<8>("homuhomu");
x.resize(4);
SPROUT_ASSERT_MSG(x.size() == 4 && x == "homu", "string is resized to 4.");
Header
========================================
| ``sprout/string/string.hpp``
| Convenience header: ``sprout/string.hpp``