📄 new-iter-concepts.rst
字号:
``pointer`` associated types.The other set of concepts handles traversal:- Incrementable Iterator- Single Pass Iterator- Forward Traversal Iterator- Bidirectional Traversal Iterator- Random Access Traversal IteratorThe refinement relationships for the traversal concepts are in thefollowing diagram... image:: traversal.pngIn addition to the iterator movement operators, such as``operator++``, the traversal concepts also include requirements onposition comparison such as ``operator==`` and ``operator<``. Thereason for the fine grain slicing of the concepts into theIncrementable and Single Pass is to provide concepts that are exactmatches with the original input and output iterator requirements.This proposal also includes a concept for specifying when an iteratoris interoperable with another iterator, in the sense that ``int*`` isinteroperable with ``int const*``.- Interoperable IteratorsThe relationship between the new iterator concepts and the old aregiven in the following diagram... image:: oldeqnew.pngLike the old iterator requirements, we provide tags for purposes ofdispatching based on the traversal concepts. The tags are related viainheritance so that a tag is convertible to another tag if the conceptassociated with the first tag is a refinement of the second tag.Our design reuses ``iterator_traits<Iter>::iterator_category`` toindicate an iterator's traversal capability. To specifycapabilities not captured by any old-style iterator category, aniterator designer can use an ``iterator_category`` type that isconvertible to both the the most-derived old iterator category tagwhich fits, and the appropriate new iterator traversal tag... dwa2003/1/2: Note that we are not *requiring* convertibility to a new-style traversal tag in order to meet new concepts. Old-style iterators still fit, after all.We do not provide tags for the purposes of dispatching based on theaccess concepts, in part because we could not find a way toautomatically infer the right access tags for old-style iterators.An iterator's writability may be dependent on the assignability ofits ``value_type`` and there's no known way to detect whether anarbitrary type is assignable. Fortunately, the need fordispatching based on access capability is not as great as the needfor dispatching based on traversal capability.A difficult design decision concerned the ``operator[]``. The directapproach for specifying ``operator[]`` would have a return type of``reference``; the same as ``operator*``. However, going in thisdirection would mean that an iterator satisfying the old Random AccessIterator requirements would not necessarily be a model of Readable orWritable Lvalue Iterator. Instead we have chosen a design thatmatches the preferred resolution of `issue 299`_: ``operator[]`` isonly required to return something convertible to the ``value_type``(for a Readable Iterator), and is required to support assignment``i[n] = t`` (for a Writable Iterator).=============== Proposed Text===============Addition to [lib.iterator.requirements]=======================================Iterator Value Access Concepts [lib.iterator.value.access]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++In the tables below, ``X`` is an iterator type, ``a`` is a constantobject of type ``X``, ``R`` is``std::iterator_traits<X>::reference``, ``T`` is``std::iterator_traits<X>::value_type``, and ``v`` is a constantobject of type ``T``... _Readable Iterator:Readable Iterators [lib.readable.iterators]-------------------------------------------A class or built-in type ``X`` models the *Readable Iterator* conceptfor value type ``T`` if, in addition to ``X`` being Assignable andCopy Constructible, the following expressions are valid and respectthe stated semantics. ``U`` is the type of any specified member oftype ``T``.+-----------------------------------------------------------------------------------------------------------------------------+|Readable Iterator Requirements (in addition to Assignable and Copy Constructible) |+-----------------------------------+------------------------+----------------------------------------------------------------+|Expression |Return Type |Note/Precondition |+===================================+========================+================================================================+|``iterator_traits<X>::value_type`` |``T`` |Any non-reference, || | |non-cv-qualified type |+-----------------------------------+------------------------+----------------------------------------------------------------+|``*a`` | Convertible to ``T`` |pre: ``a`` is dereferenceable. If ``a == b`` then ``*a`` || | | is equivalent to ``*b``. |+-----------------------------------+------------------------+----------------------------------------------------------------+|``a->m`` |``U&`` |pre: ``pre: (*a).m`` is well-defined. Equivalent to ``(*a).m``. |+-----------------------------------+------------------------+----------------------------------------------------------------+.. We won't say anything about iterator_traits<X>::reference until the DR is resolved. -JGS.. _Writable Iterator:Writable Iterators [lib.writable.iterators]-------------------------------------------A class or built-in type ``X`` models the *Writable Iterator* conceptif, in addition to ``X`` being Copy Constructible, the followingexpressions are valid and respect the stated semantics. WritableIterators have an associated *set of value types*.+---------------------------------------------------------------------+|Writable Iterator Requirements (in addition to Copy Constructible) |+-------------------------+--------------+----------------------------+|Expression |Return Type |Precondition |+=========================+==============+============================+|``*a = o`` | | pre: The type of ``o`` || | | is in the set of || | | value types of ``X`` |+-------------------------+--------------+----------------------------+Swappable Iterators [lib.swappable.iterators]---------------------------------------------A class or built-in type ``X`` models the *Swappable Iterator* conceptif, in addition to ``X`` being Copy Constructible, the followingexpressions are valid and respect the stated semantics.+---------------------------------------------------------------------+|Swappable Iterator Requirements (in addition to Copy Constructible) |+-------------------------+-------------+-----------------------------+|Expression |Return Type |Postcondition |+=========================+=============+=============================+|``iter_swap(a, b)`` |``void`` |the pointed to values are || | |exchanged |+-------------------------+-------------+-----------------------------+[*Note:* An iterator that is a model of the `Readable Iterator`_ and`Writable Iterator`_ concepts is also a model of *SwappableIterator*. *--end note*]Lvalue Iterators [lib.lvalue.iterators]---------------------------------------The *Lvalue Iterator* concept adds the requirement that the returntype of ``operator*`` type be a reference to the value type of theiterator. +-------------------------------------------------------------+| Lvalue Iterator Requirements |+-------------+-----------+-----------------------------------+|Expression |Return Type|Note/Assertion |+=============+===========+===================================+|``*a`` | ``T&`` |``T`` is *cv* || | |``iterator_traits<X>::value_type`` || | |where *cv* is an optional || | |cv-qualification. pre: ``a`` is || | |dereferenceable. |+-------------+-----------+-----------------------------------+If ``X`` is a `Writable Iterator`_ then ``a == b`` if and only if``*a`` is the same object as ``*b``. If ``X`` is a `ReadableIterator`_ then ``a == b`` implies ``*a`` is the same object as``*b``.Iterator Traversal Concepts [lib.iterator.traversal]++++++++++++++++++++++++++++++++++++++++++++++++++++In the tables below, ``X`` is an iterator type, ``a`` and ``b`` areconstant objects of type ``X``, ``r`` and ``s`` are mutable objects oftype ``X``, ``T`` is ``std::iterator_traits<X>::value_type``, and``v`` is a constant object of type ``T``.Incrementable Iterators [lib.incrementable.iterators]-----------------------------------------------------A class or built-in type ``X`` models the *Incrementable Iterator*concept if, in addition to ``X`` being Assignable and CopyConstructible, the following expressions are valid and respect thestated semantics.+------------------------------------------------------------------------------------+|Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible) || |+--------------------------------+-------------------------------+-------------------+|Expression |Return Type |Assertion |+================================+===============================+===================+|``++r`` |``X&`` |``&r == &++r`` |+--------------------------------+-------------------------------+-------------------+|``r++`` | | |+--------------------------------+-------------------------------+-------------------+|``*r++`` | | |+--------------------------------+-------------------------------+-------------------+|``iterator_traversal<X>::type`` |Convertible to | || |``incrementable_traversal_tag``| |+--------------------------------+-------------------------------+-------------------+If ``X`` is a `Writable Iterator`_ then ``X a(r++);`` is equivalentto ``X a(r); ++r;`` and ``*r++ = o`` is equivalentto ``*r = o; ++r``.If ``X`` is a `Readable Iterator`_ then ``T z(*r++);`` is equivalentto ``T z(*r); ++r;``. .. TR1: incrementable_iterator_tag changed to incrementable_traversal_tag for consistency.Single Pass Iterators [lib.single.pass.iterators]-------------------------------------------------A class or built-in type ``X`` models the *Single Pass Iterator*concept if the following expressions are valid and respect the statedsemantics.+----------------------------------------------------------------------------------------------------------------+|Single Pass Iterator Requirements (in addition to Incrementable Iterator and Equality Comparable) || |+----------------------------------------+-----------------------------+-------------+---------------------------+|Expression |Return Type | Operational |Assertion/ | | | | Semantics |Pre-/Post-condition |+========================================+=============================+=============+===========================+|``++r`` |``X&`` | |pre: ``r`` is || | | |dereferenceable; post: || | | |``r`` is dereferenceable or|| | | |``r`` is past-the-end |+----------------------------------------+-----------------------------+-------------+---------------------------+|``a == b`` |convertible to ``bool`` | |``==`` is an equivalence || | | |relation over its domain |+----------------------------------------+-----------------------------+-------------+---------------------------+|``a != b`` |convertible to ``bool`` |``!(a == b)``| |+----------------------------------------+-----------------------------+-------------+---------------------------+|``iterator_traits<X>::difference_type`` |A signed integral type | | || |representing the distance | | || |between iterators | | |+----------------------------------------+-----------------------------+-------------+---------------------------+|``iterator_traversal<X>::type`` |Convertible to | | || |``single_pass_traversal_tag``| | |+----------------------------------------+-----------------------------+-------------+---------------------------+.. TR1: single_pass_iterator_tag changed to single_pass_traversal_tag for consistencyForward Traversal Iterators [lib.forward.traversal.iterators]-------------------------------------------------------------A class or built-in type ``X`` models the *Forward Traversal Iterator*concept if, in addition to ``X`` meeting the requirements of DefaultConstructible and Single Pass Iterator, the following expressions arevalid and respect the stated semantics. +--------------------------------------------------------------------------------------------------------+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -