mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-07-02 14:04:09 +00:00
add doc: char_traits string operations (for iterator)
This commit is contained in:
parent
0ef068c92b
commit
dd0c5f4dbb
47 changed files with 1722 additions and 60 deletions
40
source/libs/string/char_traits/assign-iterator.rst
Normal file
40
source/libs/string/char_traits/assign-iterator.rst
Normal file
|
@ -0,0 +1,40 @@
|
|||
.. _sprout-string-char_traits-assign-iterator:
|
||||
###############################################################################
|
||||
assign
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename OutputIterator>
|
||||
static OutputIterator assign(OutputIterator s, std::size_t n, char_type a);
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
| For each i in [0,n) performs ``assign(s[i], c)``.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/string.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
auto x = string<8>("homuhomu");;
|
||||
char_traits<char>::assign(x.begin(), 8, 'M');
|
||||
SPROUT_ASSERT_MSG(x[0] == 'M', "x is filled by M.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| linear.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/string/char_traits.hpp``
|
||||
| Convenience header: ``sprout/string.hpp``
|
||||
|
49
source/libs/string/char_traits/compare-iterator.rst
Normal file
49
source/libs/string/char_traits/compare-iterator.rst
Normal file
|
@ -0,0 +1,49 @@
|
|||
.. _sprout-string-char_traits-compare-iterator:
|
||||
###############################################################################
|
||||
compare
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ConstInputIterator>
|
||||
static SPROUT_CONSTEXPR int compare(char_type const* s1, ConstInputIterator s2, std::size_t n);
|
||||
|
||||
template<typename ConstInputIterator>
|
||||
static SPROUT_CONSTEXPR int compare(ConstInputIterator s1, char_type const* s2, std::size_t n);
|
||||
|
||||
template<typename ConstInputIterator1, typename ConstInputIterator2>
|
||||
static SPROUT_CONSTEXPR int compare(ConstInputIterator1 s1, ConstInputIterator2 s2, std::size_t n);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| If for each i in [0,n), ``eq(s1[i], s2[i])`` is true, return zero.
|
||||
| Otherwise, if for some j in [0,n), ``lt(s1[j], s2[j])`` is true and for each i in [0,j) ``eq(s1[i], s2[i])`` is true, return a negative value.
|
||||
| Otherwise, return a positive value.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/string.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto x = string<8>("homuhomu");
|
||||
SPROUT_STATIC_CONSTEXPR auto y = string<8>("madocchi");
|
||||
SPROUT_STATIC_CONSTEXPR auto result = char_traits<char>::compare(x.begin(), y.begin(), 8);
|
||||
static_assert(result < 0, "x is less than y.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| linear.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/string/char_traits.hpp``
|
||||
| Convenience header: ``sprout/string.hpp``
|
||||
|
46
source/libs/string/char_traits/copy-iterator.rst
Normal file
46
source/libs/string/char_traits/copy-iterator.rst
Normal file
|
@ -0,0 +1,46 @@
|
|||
.. _sprout-string-char_traits-copy-iterator:
|
||||
###############################################################################
|
||||
copy
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename OutputIterator, typename ConstInputIterator>
|
||||
static OutputIterator copy(OutputIterator s1, ConstInputIterator s2, std::size_t n);
|
||||
|
||||
Pre-condition
|
||||
========================================
|
||||
|
||||
| s2 not in [s1,s1+n).
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
| For each i in [0,n) performs ``assign(s1[i], s2[i])``.
|
||||
|
||||
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");
|
||||
char_traits<char>::copy(x.begin(), y.begin(), 8);
|
||||
SPROUT_ASSERT_MSG(x[0] == y[0], "y is copied to x.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| linear.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/string/char_traits.hpp``
|
||||
| Convenience header: ``sprout/string.hpp``
|
||||
|
|
@ -9,6 +9,11 @@ Interface
|
|||
|
||||
static char_type* copy(char_type* s1, char_type const* s2, std::size_t n);
|
||||
|
||||
Pre-condition
|
||||
========================================
|
||||
|
||||
| s2 not in [s1,s1+n).
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ Interface
|
|||
|
||||
static SPROUT_CONSTEXPR int_type eof() SPROUT_NOEXCEPT;
|
||||
|
||||
Effects
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| Equivalent to ``std::char_traits<Char>::eof()``.
|
||||
|
|
|
@ -9,7 +9,7 @@ Interface
|
|||
|
||||
static SPROUT_CONSTEXPR bool eq(char_type c1, char_type c2) SPROUT_NOEXCEPT;
|
||||
|
||||
Effects
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| Equivalent to ``std::char_traits<Char>::eq(c1, c2)``.
|
||||
|
|
|
@ -9,7 +9,7 @@ Interface
|
|||
|
||||
static SPROUT_CONSTEXPR bool eq_int_type(int_type c1, int_type c2) SPROUT_NOEXCEPT;
|
||||
|
||||
Effects
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| Equivalent to ``std::char_traits<Char>::eq_int_type(c1, c2)``.
|
||||
|
|
46
source/libs/string/char_traits/find-iterator.rst
Normal file
46
source/libs/string/char_traits/find-iterator.rst
Normal file
|
@ -0,0 +1,46 @@
|
|||
.. _sprout-string-char_traits-find-iterator:
|
||||
###############################################################################
|
||||
find
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ConstInputIterator>
|
||||
static SPROUT_CONSTEXPR ConstInputIterator find(ConstInputIterator s, std::size_t n, char_type const& a);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The smallest q in [s,s+n) such that ``eq(*q, a)`` is true, ``s + n`` otherwise.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| Pointer version returns 0 when it not found, but this function returns ``s + n``.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/string.hpp>
|
||||
#include <sprout/iterator.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto x = string<8>("homuhomu");
|
||||
SPROUT_STATIC_CONSTEXPR auto result = char_traits<char>::find(x.begin(), 8, 'm');
|
||||
static_assert(sprout::distance(x, result) == 2, "a found position is 2.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| linear.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/string/char_traits.hpp``
|
||||
| Convenience header: ``sprout/string.hpp``
|
||||
|
|
@ -20,6 +20,12 @@ char_traits
|
|||
to_int_type
|
||||
eq_int_type
|
||||
eof
|
||||
compare-iterator
|
||||
length-iterator
|
||||
find-iterator
|
||||
move-iterator
|
||||
copy-iterator
|
||||
assign-iterator
|
||||
|
||||
Interface
|
||||
========================================
|
||||
|
@ -59,8 +65,8 @@ Interface
|
|||
static SPROUT_CONSTEXPR int compare(char_type const* s1, ConstInputIterator s2, std::size_t n);
|
||||
template<typename ConstInputIterator>
|
||||
static SPROUT_CONSTEXPR int compare(ConstInputIterator s1, char_type const* s2, std::size_t n);
|
||||
template<typename ConstIterator1, typename ConstIterator2>
|
||||
static SPROUT_CONSTEXPR int compare(ConstIterator1 s1, ConstIterator2 s2, std::size_t n);
|
||||
template<typename ConstInputIterator1, typename ConstInputIterator2>
|
||||
static SPROUT_CONSTEXPR int compare(ConstInputIterator1 s1, ConstInputIterator2 s2, std::size_t n);
|
||||
template<typename ConstInputIterator>
|
||||
static SPROUT_CONSTEXPR std::size_t length(ConstInputIterator s);
|
||||
template<typename ConstInputIterator>
|
||||
|
@ -137,7 +143,7 @@ string operations (for iterator)
|
|||
function
|
||||
======================================== ===============================================================================
|
||||
:doc:`compare <./compare-iterator>`
|
||||
:doc:`eqlength<./length-iterator>`
|
||||
:doc:`length<./length-iterator>`
|
||||
:doc:`find <./find-iterator>`
|
||||
:doc:`move <./move-iterator>`
|
||||
:doc:`copy <./copy-iterator>`
|
||||
|
|
40
source/libs/string/char_traits/length-iterator.rst
Normal file
40
source/libs/string/char_traits/length-iterator.rst
Normal file
|
@ -0,0 +1,40 @@
|
|||
.. _sprout-string-char_traits-length-iterator:
|
||||
###############################################################################
|
||||
length
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ConstInputIterator>
|
||||
static SPROUT_CONSTEXPR std::size_t length(ConstInputIterator s);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The smallest i such that ``eq(s[i], char_type())`` is true.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/string.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto x = string<8>("homuhomu");
|
||||
SPROUT_STATIC_CONSTEXPR auto result = char_traits<char>::length(x.begin());
|
||||
static_assert(result == 8, "length of x is 8.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| linear.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/string/char_traits.hpp``
|
||||
| Convenience header: ``sprout/string.hpp``
|
||||
|
|
@ -9,7 +9,7 @@ Interface
|
|||
|
||||
static SPROUT_CONSTEXPR bool lt(char_type c1, char_type c2) SPROUT_NOEXCEPT;
|
||||
|
||||
Effects
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| Equivalent to ``std::char_traits<Char>::lt(c1, c2)``.
|
||||
|
|
42
source/libs/string/char_traits/move-iterator.rst
Normal file
42
source/libs/string/char_traits/move-iterator.rst
Normal file
|
@ -0,0 +1,42 @@
|
|||
.. _sprout-string-char_traits-move-iterator:
|
||||
###############################################################################
|
||||
move
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename OutputIterator, typename ConstInputIterator>
|
||||
static OutputIterator move(OutputIterator s1, ConstInputIterator s2, std::size_t n);
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
| For each i in [0,n) performs ``assign(s1[i], p2[i])``.
|
||||
| Copies correctly even where the ranges [s2,s2+n) and [s1,s1+n) overlap.
|
||||
|
||||
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");
|
||||
char_traits<char>::move(x.begin(), y.begin(), 8);
|
||||
SPROUT_ASSERT_MSG(x[0] == y[0], "y is copied to x.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| linear.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/string/char_traits.hpp``
|
||||
| Convenience header: ``sprout/string.hpp``
|
||||
|
|
@ -9,7 +9,7 @@ Interface
|
|||
|
||||
static SPROUT_CONSTEXPR int_type not_eof(int_type c) SPROUT_NOEXCEPT;
|
||||
|
||||
Effects
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| Equivalent to ``std::char_traits<Char>::not_eof(c)``.
|
||||
|
|
|
@ -9,7 +9,7 @@ Interface
|
|||
|
||||
static SPROUT_CONSTEXPR char_type to_char_type(int_type c) SPROUT_NOEXCEPT;
|
||||
|
||||
Effects
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| Equivalent to ``std::char_traits<Char>::to_char_type(c)``.
|
||||
|
|
|
@ -9,7 +9,7 @@ Interface
|
|||
|
||||
static SPROUT_CONSTEXPR int_type to_int_type(char_type c) SPROUT_NOEXCEPT;
|
||||
|
||||
Effects
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| Equivalent to ``std::char_traits<Char>::to_int_type(c)``.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue