randomaccesstraversal.rst

来自「Boost provides free peer-reviewed portab」· RST 代码 · 共 68 行

RST
68
字号
.. Copyright David Abrahams 2006. Distributed under the Boost.. Software License, Version 1.0. (See accompanying.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)Random Access Traversal Concept...............................A class or built-in type ``X`` models the *Random Access Traversal*concept if the following expressions are valid and respect the statedsemantics.  In the table below, ``Distance`` is``iterator_traits<X>::difference_type`` and ``n`` represents aconstant object of type ``Distance``.+------------------------------------------------------------------------------------------------------------------+|Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal)                            |+-------------------------------+---------------------------------+-------------------------+----------------------+|Expression                     |Return Type                      |Operational Semantics    |Assertion/            ||                               |                                 |                         |Precondition          |+===============================+=================================+=========================+======================+|``r += n``                     |``X&``                           |::                       |                      ||                               |                                 |                         |                      ||                               |                                 | {                       |                      ||                               |                                 |   Distance m = n;       |                      ||                               |                                 |   if (m >= 0)           |                      ||                               |                                 |     while (m--)         |                      ||                               |                                 |       ++r;              |                      ||                               |                                 |   else                  |                      ||                               |                                 |     while (m++)         |                      ||                               |                                 |       --r;              |                      ||                               |                                 |   return r;             |                      ||                               |                                 | }                       |                      |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a + n``, ``n + a``           |``X``                            |``{ X tmp = a; return tmp|                      ||                               |                                 |+= n; }``                |                      ||                               |                                 |                         |                      |+-------------------------------+---------------------------------+-------------------------+----------------------+|``r -= n``                     |``X&``                           |``return r += -n``       |                      |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a - n``                      |``X``                            |``{ X tmp = a; return tmp|                      ||                               |                                 |-= n; }``                |                      ||                               |                                 |                         |                      |+-------------------------------+---------------------------------+-------------------------+----------------------+|``b - a``                      |``Distance``                     |``a < b ?  distance(a,b) |pre: there exists a   ||                               |                                 |: -distance(b,a)``       |value ``n`` of        ||                               |                                 |                         |``Distance`` such that||                               |                                 |                         |``a + n == b``.  ``b  ||                               |                                 |                         |== a + (b - a)``.     |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a[n]``                       |convertible to T                 |``*(a + n)``             |pre: a is a *Readable ||                               |                                 |                         |Iterator*             |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a[n] = v``                   |convertible to T                 |``*(a + n) = v``         |pre: a is a *Writable ||                               |                                 |                         |iterator*             |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a < b``                      |convertible to ``bool``          |``b - a > 0``            |``<`` is a total      ||                               |                                 |                         |ordering relation     |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a > b``                      |convertible to ``bool``          |``b < a``                |``>`` is a total      ||                               |                                 |                         |ordering relation     |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a >= b``                     |convertible to ``bool``          |``!(a < b)``             |                      |+-------------------------------+---------------------------------+-------------------------+----------------------+|``a <= b``                     |convertible to ``bool``          |``!(a > b)``             |                      |+-------------------------------+---------------------------------+-------------------------+----------------------+|``iterator_traversal<X>::type``|Convertible to                   |                         |                      ||                               |``random_access_traversal_tag``  |                         |                      |+-------------------------------+---------------------------------+-------------------------+----------------------+

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?