diff --git a/doc/.cvsignore b/doc/.cvsignore deleted file mode 100755 index 59a4657..0000000 --- a/doc/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -GNUmakefile diff --git a/doc/BidirectionalTraversal.html b/doc/BidirectionalTraversal.html deleted file mode 100644 index 5bc8342..0000000 --- a/doc/BidirectionalTraversal.html +++ /dev/null @@ -1,351 +0,0 @@ - - - - - - -Bidirectional Traversal Concept - - - -
-

Bidirectional Traversal Concept

- - - -

A class or built-in type X models the Bidirectional Traversal -concept if, in addition to X meeting the requirements of Forward -Traversal Iterator, the following expressions are valid and respect -the stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - -
Bidirectional Traversal Iterator Requirements (in addition to Forward Traversal -Iterator)
ExpressionReturn TypeAssertion/Semantics / -Pre-/Post-condition
--rX&pre: there exists -s such that r -== ++s. post: -s is -dereferenceable. ---(++r) == r. ---r == --s -implies r == -s. &r == &--r.
r--convertible to const X&
-{
-  X tmp = r;
-  --r;
-  return tmp;
-}
-
-
iterator_traversal<X>::typeConvertible to -bidirectional_traversal_tag 
-
- - diff --git a/doc/BidirectionalTraversal.rst b/doc/BidirectionalTraversal.rst deleted file mode 100755 index a62b8bd..0000000 --- a/doc/BidirectionalTraversal.rst +++ /dev/null @@ -1,41 +0,0 @@ -.. 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) - -Bidirectional Traversal Concept -............................... - -A class or built-in type ``X`` models the *Bidirectional Traversal* -concept if, in addition to ``X`` meeting the requirements of Forward -Traversal Iterator, the following expressions are valid and respect -the stated semantics. - -+--------------------------------------------------------------------------------------+ -|Bidirectional Traversal Iterator Requirements (in addition to Forward Traversal | -|Iterator) | -+--------------------------------+-------------------------------+---------------------+ -|Expression |Return Type |Assertion/Semantics /| -| | |Pre-/Post-condition | -+================================+===============================+=====================+ -|``--r`` |``X&`` |pre: there exists | -| | |``s`` such that ``r | -| | |== ++s``. post: | -| | |``s`` is | -| | |dereferenceable. | -| | |``--(++r) == r``. | -| | |``--r == --s`` | -| | |implies ``r == | -| | |s``. ``&r == &--r``. | -+--------------------------------+-------------------------------+---------------------+ -|``r--`` |convertible to ``const X&`` |:: | -| | | | -| | | { | -| | | X tmp = r; | -| | | --r; | -| | | return tmp; | -| | | } | -+--------------------------------+-------------------------------+---------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``bidirectional_traversal_tag``| | -| | | | -+--------------------------------+-------------------------------+---------------------+ diff --git a/doc/ForwardTraversal.html b/doc/ForwardTraversal.html deleted file mode 100644 index 934aa56..0000000 --- a/doc/ForwardTraversal.html +++ /dev/null @@ -1,342 +0,0 @@ - - - - - - -Forward Traversal Concept - - - -
-

Forward Traversal Concept

- - - -

A class or built-in type X models the Forward Traversal -concept if, in addition to X meeting the requirements of Default -Constructible and Single Pass Iterator, the following expressions are -valid and respect the stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Forward Traversal Iterator Requirements (in addition to Default Constructible and Single Pass Iterator)
ExpressionReturn TypeAssertion/Note
X u;X&note: u may have a -singular value.
++rX&r == s and r is -dereferenceable implies -++r == ++s.
iterator_traits<X>::difference_typeA signed integral type representing -the distance between iterators 
iterator_traversal<X>::typeConvertible to -forward_traversal_tag 
-
- - diff --git a/doc/ForwardTraversal.rst b/doc/ForwardTraversal.rst deleted file mode 100755 index 80dd9c7..0000000 --- a/doc/ForwardTraversal.rst +++ /dev/null @@ -1,31 +0,0 @@ -.. 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) - -Forward Traversal Concept -......................... - -A class or built-in type ``X`` models the *Forward Traversal* -concept if, in addition to ``X`` meeting the requirements of Default -Constructible and Single Pass Iterator, the following expressions are -valid and respect the stated semantics. - -+--------------------------------------------------------------------------------------------------------+ -|Forward Traversal Iterator Requirements (in addition to Default Constructible and Single Pass Iterator) | -+---------------------------------------+-----------------------------------+----------------------------+ -|Expression |Return Type |Assertion/Note | -+=======================================+===================================+============================+ -|``X u;`` |``X&`` |note: ``u`` may have a | -| | |singular value. | -+---------------------------------------+-----------------------------------+----------------------------+ -|``++r`` |``X&`` |``r == s`` and ``r`` is | -| | |dereferenceable implies | -| | |``++r == ++s.`` | -+---------------------------------------+-----------------------------------+----------------------------+ -|``iterator_traits::difference_type``|A signed integral type representing| | -| |the distance between iterators | | -| | | | -+---------------------------------------+-----------------------------------+----------------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``forward_traversal_tag`` | | -+---------------------------------------+-----------------------------------+----------------------------+ diff --git a/doc/GNUmakefile b/doc/GNUmakefile deleted file mode 100755 index 85917f7..0000000 --- a/doc/GNUmakefile +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright David Abrahams 2004. 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) - -ECHO = /bin/echo - -all: - @${ECHO} "/libs/iterator/doc/GNUmakefile should be replaced by" - @${ECHO} - @${ECHO} " http://www.boost-consulting.com/writing/GNUmakefile," - @${ECHO} - @${ECHO} "before proceeding. That file is not included in the Boost" - @${ECHO} "distribution because it is licensed under the GPL, which violates" - @${ECHO} "Boost license requirements." - diff --git a/doc/IncrementableIterator.html b/doc/IncrementableIterator.html deleted file mode 100644 index c42cfff..0000000 --- a/doc/IncrementableIterator.html +++ /dev/null @@ -1,341 +0,0 @@ - - - - - - -Incrementable Iterator Concept - - - -
-

Incrementable Iterator Concept

- - - -

A class or built-in type X models the Incrementable Iterator -concept if, in addition to X being Assignable and Copy -Constructible, the following expressions are valid and respect the -stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - -
Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible)
ExpressionReturn TypeAssertion/Semantics
++rX&&r == &++r
r++X
-{
-   X tmp = r;
-   ++r;
-   return tmp;
-}
-
-
iterator_traversal<X>::typeConvertible to -incrementable_traversal_tag 
-
- - diff --git a/doc/IncrementableIterator.rst b/doc/IncrementableIterator.rst deleted file mode 100755 index a1f92ec..0000000 --- a/doc/IncrementableIterator.rst +++ /dev/null @@ -1,32 +0,0 @@ -.. 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) - -Incrementable Iterator Concept -.............................. - -A class or built-in type ``X`` models the *Incrementable Iterator* -concept if, in addition to ``X`` being Assignable and Copy -Constructible, the following expressions are valid and respect the -stated semantics. - - -+-------------------------------------------------------------------------------------+ -|Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible) | -| | -+--------------------------------+-------------------------------+--------------------+ -|Expression |Return Type |Assertion/Semantics | -+================================+===============================+====================+ -|``++r`` |``X&`` |``&r == &++r`` | -+--------------------------------+-------------------------------+--------------------+ -|``r++`` |``X`` |:: | -| | | | -| | | { | -| | | X tmp = r; | -| | | ++r; | -| | | return tmp; | -| | | } | -+--------------------------------+-------------------------------+--------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``incrementable_traversal_tag``| | -+--------------------------------+-------------------------------+--------------------+ diff --git a/doc/InteroperableIterator.rst b/doc/InteroperableIterator.rst deleted file mode 100644 index 3632ff2..0000000 --- a/doc/InteroperableIterator.rst +++ /dev/null @@ -1,61 +0,0 @@ -.. 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) - -Interoperable Iterator Concept -.............................. - -A class or built-in type ``X`` that models Single Pass Iterator is -*interoperable with* a class or built-in type ``Y`` that also models -Single Pass Iterator if the following expressions are valid and -respect the stated semantics. In the tables below, ``x`` is an object -of type ``X``, ``y`` is an object of type ``Y``, ``Distance`` is -``iterator_traits::difference_type``, and ``n`` represents a -constant object of type ``Distance``. - -+-----------+-----------------------+---------------------------------------------------+ -|Expression |Return Type |Assertion/Precondition/Postcondition | -+===========+=======================+===================================================+ -|``y = x`` |``Y`` |post: ``y == x`` | -+-----------+-----------------------+---------------------------------------------------+ -|``Y(x)`` |``Y`` |post: ``Y(x) == x`` | -+-----------+-----------------------+---------------------------------------------------+ -|``x == y`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``y == x`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``x != y`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``y != x`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | -+-----------+-----------------------+---------------------------------------------------+ - -If ``X`` and ``Y`` both model Random Access Traversal Iterator then -the following additional requirements must be met. - -+-----------+-----------------------+---------------------+--------------------------------------+ -|Expression |Return Type |Operational Semantics|Assertion/ Precondition | -+===========+=======================+=====================+======================================+ -|``x < y`` |convertible to ``bool``|``y - x > 0`` |``<`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y < x`` |convertible to ``bool``|``x - y > 0`` |``<`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x > y`` |convertible to ``bool``|``y < x`` |``>`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y > x`` |convertible to ``bool``|``x < y`` |``>`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x >= y`` |convertible to ``bool``|``!(x < y)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y >= x`` |convertible to ``bool``|``!(y < x)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x <= y`` |convertible to ``bool``|``!(x > y)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y <= x`` |convertible to ``bool``|``!(y > x)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y - x`` |``Distance`` |``distance(Y(x),y)`` |pre: there exists a value ``n`` of | -| | | |``Distance`` such that ``x + n == y``.| -| | | |``y == x + (y - x)``. | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x - y`` |``Distance`` |``distance(y,Y(x))`` |pre: there exists a value ``n`` of | -| | | |``Distance`` such that ``y + n == x``.| -| | | |``x == y + (x - y)``. | -+-----------+-----------------------+---------------------+--------------------------------------+ diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 deleted file mode 100644 index 2fe0c7a..0000000 --- a/doc/Jamfile.v2 +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright Thomas Witt 2005. Use, modification, and distribution are -# subject to 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) - -using quickbook ; - -xml iterator - : - quickbook/iterator.qbk - ; - -boostbook standalone - : - iterator - : - toc.max.depth=3 - toc.section.depth=3 - chunk.section.depth=4 - ; - diff --git a/doc/LvalueIterator.html b/doc/LvalueIterator.html deleted file mode 100644 index 6575694..0000000 --- a/doc/LvalueIterator.html +++ /dev/null @@ -1,331 +0,0 @@ - - - - - - -Lvalue Iterator Concept - - - -
-

Lvalue Iterator Concept

- - - -

The Lvalue Iterator concept adds the requirement that the return -type of operator* type be a reference to the value type of the -iterator.

- ----- - - - - - - - - - - - - - - -
Lvalue Iterator Requirements
ExpressionReturn TypeNote/Assertion
*aT&T is cv -iterator_traits<X>::value_type -where cv is an optional -cv-qualification. -pre: a is -dereferenceable. If a -== b then *a is -equivalent to *b.
-
- - diff --git a/doc/LvalueIterator.rst b/doc/LvalueIterator.rst deleted file mode 100755 index 39c2672..0000000 --- a/doc/LvalueIterator.rst +++ /dev/null @@ -1,25 +0,0 @@ -.. 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) - -Lvalue Iterator Concept -....................... - -The *Lvalue Iterator* concept adds the requirement that the return -type of ``operator*`` type be a reference to the value type of the -iterator. - -+-------------------------------------------------------------+ -| Lvalue Iterator Requirements | -+-------------+-----------+-----------------------------------+ -|Expression |Return Type|Note/Assertion | -+=============+===========+===================================+ -|``*a`` | ``T&`` |``T`` is *cv* | -| | |``iterator_traits::value_type`` | -| | |where *cv* is an optional | -| | |cv-qualification. | -| | |pre: ``a`` is | -| | |dereferenceable. If ``a | -| | |== b`` then ``*a`` is | -| | |equivalent to ``*b``. | -+-------------+-----------+-----------------------------------+ diff --git a/doc/RandomAccessTraversal.html b/doc/RandomAccessTraversal.html deleted file mode 100644 index 4dd09ca..0000000 --- a/doc/RandomAccessTraversal.html +++ /dev/null @@ -1,409 +0,0 @@ - - - - - - -Random Access Traversal Concept - - - -
-

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 stated -semantics. In the table below, Distance is -iterator_traits<X>::difference_type and n represents a -constant object of type Distance.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal)
ExpressionReturn TypeOperational SemanticsAssertion/ -Precondition
r += nX&
-{
-  Distance m = n;
-  if (m >= 0)
-    while (m--)
-      ++r;
-  else
-    while (m++)
-      --r;
-  return r;
-}
-
-
 
a + n, n + aX{ X tmp = a; return tmp -+= n; } 
r -= nX&return r += -n 
a - nX{ X tmp = a; return tmp --= n; } 
b - aDistancea < b ?  distance(a,b) -: -distance(b,a)pre: there exists 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] = vconvertible to T*(a + n) = vpre: a is a Writable -iterator
a < bconvertible to boolb - a > 0< is a total -ordering relation
a > bconvertible to boolb < a> is a total -ordering relation
a >= bconvertible to bool!(a < b) 
a <= bconvertible to bool!(a > b) 
iterator_traversal<X>::typeConvertible to -random_access_traversal_tag  
-
- - diff --git a/doc/RandomAccessTraversal.rst b/doc/RandomAccessTraversal.rst deleted file mode 100644 index 490faf6..0000000 --- a/doc/RandomAccessTraversal.rst +++ /dev/null @@ -1,67 +0,0 @@ -.. 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 stated -semantics. In the table below, ``Distance`` is -``iterator_traits::difference_type`` and ``n`` represents a -constant 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::type``|Convertible to | | | -| |``random_access_traversal_tag`` | | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ diff --git a/doc/ReadableIterator.html b/doc/ReadableIterator.html deleted file mode 100644 index b6873c4..0000000 --- a/doc/ReadableIterator.html +++ /dev/null @@ -1,339 +0,0 @@ - - - - - - -Readable Iterator Concept - - - -
-

Readable Iterator Concept

- - - -

A class or built-in type X models the Readable Iterator concept -for value type T if, in addition to X being Assignable and -Copy Constructible, the following expressions are valid and respect -the stated semantics. U is the type of any specified member of -type T.

- ----- - - - - - - - - - - - - - - - - - - - - - - -
Readable Iterator Requirements (in addition to Assignable and Copy Constructible)
ExpressionReturn TypeNote/Precondition
iterator_traits<X>::value_typeTAny non-reference, -non-cv-qualified type
*aConvertible to T
-
pre: a is dereferenceable. If a == b then *a
-
is equivalent to *b.
-
-
a->mU&pre: pre: (*a).m is well-defined. Equivalent to (*a).m.
-
- - diff --git a/doc/ReadableIterator.rst b/doc/ReadableIterator.rst deleted file mode 100755 index 27f79f8..0000000 --- a/doc/ReadableIterator.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. 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) - -Readable Iterator Concept -......................... - -A class or built-in type ``X`` models the *Readable Iterator* concept -for value type ``T`` if, in addition to ``X`` being Assignable and -Copy Constructible, the following expressions are valid and respect -the stated semantics. ``U`` is the type of any specified member of -type ``T``. - -+-----------------------------------------------------------------------------------------------------------------------------+ -|Readable Iterator Requirements (in addition to Assignable and Copy Constructible) | -+-----------------------------------+------------------------+----------------------------------------------------------------+ -|Expression |Return Type |Note/Precondition | -+===================================+========================+================================================================+ -|``iterator_traits::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``. | -+-----------------------------------+------------------------+----------------------------------------------------------------+ diff --git a/doc/SinglePassIterator.html b/doc/SinglePassIterator.html deleted file mode 100644 index 9a725e7..0000000 --- a/doc/SinglePassIterator.html +++ /dev/null @@ -1,343 +0,0 @@ - - - - - - -Single Pass Iterator Concept - - - -
-

Single Pass Iterator Concept

- - - -

A class or built-in type X models the Single Pass Iterator -concept if the following expressions are valid and respect the stated -semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Single Pass Iterator Requirements (in addition to Incrementable Iterator and Equality -Comparable)
ExpressionReturn TypeAssertion/Semantics / -Pre-/Post-condition
++rX&pre: r is -dereferenceable; post: -r is dereferenceable or -r is past-the-end
a == bconvertible to bool== is an equivalence -relation over its domain
a != bconvertible to bool!(a == b)
iterator_traversal<X>::typeConvertible to -single_pass_traversal_tag 
-
- - diff --git a/doc/SinglePassIterator.rst b/doc/SinglePassIterator.rst deleted file mode 100755 index eaa50e0..0000000 --- a/doc/SinglePassIterator.rst +++ /dev/null @@ -1,32 +0,0 @@ -.. 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) - -Single Pass Iterator Concept -............................ - -A class or built-in type ``X`` models the *Single Pass Iterator* -concept if the following expressions are valid and respect the stated -semantics. - - -+------------------------------------------------------------------------------------------+ -|Single Pass Iterator Requirements (in addition to Incrementable Iterator and Equality | -|Comparable) | -+--------------------------------+-----------------------------+---------------------------+ -|Expression |Return Type |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_traversal::type`` |Convertible to | | -| |``single_pass_traversal_tag``| | -+--------------------------------+-----------------------------+---------------------------+ diff --git a/doc/SwappableIterator.html b/doc/SwappableIterator.html deleted file mode 100644 index c11b570..0000000 --- a/doc/SwappableIterator.html +++ /dev/null @@ -1,329 +0,0 @@ - - - - - - -Swappable Iterator Concept - - - -
-

Swappable Iterator Concept

- - - -

A class or built-in type X models the Swappable Iterator concept -if, in addition to X being Copy Constructible, the following -expressions are valid and respect the stated semantics.

- ----- - - - - - - - - - - - - - - -
Swappable Iterator Requirements (in addition to Copy Constructible)
ExpressionReturn TypePostcondition
iter_swap(a, b)voidthe pointed to values are -exchanged
-
-
[Note: An iterator that is a model of the Readable and Writable Iterator concepts
-
is also a model of Swappable Iterator. --end note]
-
-
- - diff --git a/doc/SwappableIterator.rst b/doc/SwappableIterator.rst deleted file mode 100755 index 55554e7..0000000 --- a/doc/SwappableIterator.rst +++ /dev/null @@ -1,23 +0,0 @@ -.. 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) - -Swappable Iterator Concept -.......................... - -A class or built-in type ``X`` models the *Swappable Iterator* concept -if, in addition to ``X`` being Copy Constructible, the following -expressions 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* and *Writable Iterator* concepts - is also a model of *Swappable Iterator*. *--end note*] - diff --git a/doc/WritableIterator.html b/doc/WritableIterator.html deleted file mode 100644 index 76d621d..0000000 --- a/doc/WritableIterator.html +++ /dev/null @@ -1,327 +0,0 @@ - - - - - - -Writable Iterator Concept - - - -
-

Writable Iterator Concept

- - - -

A class or built-in type X models the Writable Iterator concept -if, in addition to X being Copy Constructible, the following -expressions are valid and respect the stated semantics. Writable -Iterators have an associated set of value types.

- ----- - - - - - - - - - - - - - - -
Writable Iterator Requirements (in addition to Copy Constructible)
ExpressionReturn TypePrecondition
*a = o pre: The type of o -is in the set of -value types of X
-
- - diff --git a/doc/WritableIterator.rst b/doc/WritableIterator.rst deleted file mode 100755 index 49b6e16..0000000 --- a/doc/WritableIterator.rst +++ /dev/null @@ -1,21 +0,0 @@ -.. 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) - -Writable Iterator Concept -......................... - -A class or built-in type ``X`` models the *Writable Iterator* concept -if, in addition to ``X`` being Copy Constructible, the following -expressions are valid and respect the stated semantics. Writable -Iterators 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`` | -+-------------------------+--------------+----------------------------+ diff --git a/doc/access.png b/doc/access.png deleted file mode 100644 index 80011dc..0000000 Binary files a/doc/access.png and /dev/null differ diff --git a/doc/access2old.png b/doc/access2old.png deleted file mode 100644 index 8a87b84..0000000 Binary files a/doc/access2old.png and /dev/null differ diff --git a/doc/counting_iterator.html b/doc/counting_iterator.html deleted file mode 100644 index 63136f0..0000000 --- a/doc/counting_iterator.html +++ /dev/null @@ -1,577 +0,0 @@ - - - - - - -Counting Iterator - - - - - - - -
-

Counting Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract:

How would you fill up a vector with the numbers zero -through one hundred using std::copy()? The only iterator -operation missing from builtin integer types is an -operator*() that returns the current value of the integer. -The counting iterator adaptor adds this crucial piece of -functionality to whatever type it wraps. One can use the -counting iterator adaptor not only with integer types, but with -any incrementable type.

- - - -

counting_iterator adapts an object by adding an operator* that -returns the current value of the object. All other iterator operations -are forwarded to the adapted object.

-
- -
-

counting_iterator synopsis

- - - -
-template <
-    class Incrementable
-  , class CategoryOrTraversal = use_default
-  , class Difference = use_default
->
-class counting_iterator
-{
-public:
-    typedef Incrementable value_type;
-    typedef const Incrementable& reference;
-    typedef const Incrementable* pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    counting_iterator();
-    counting_iterator(counting_iterator const& rhs);
-    explicit counting_iterator(Incrementable x);
-    Incrementable const& base() const;
-    reference operator*() const;
-    counting_iterator& operator++();
-    counting_iterator& operator--();
-private:
-    Incrementable m_inc; // exposition
-};
-
-

If the Difference argument is use_default then -difference_type is an unspecified signed integral -type. Otherwise difference_type is Difference.

-

iterator_category is determined according to the following -algorithm:

-
-if (CategoryOrTraversal is not use_default)
-    return CategoryOrTraversal
-else if (numeric_limits<Incrementable>::is_specialized)
-    return iterator-category(
-        random_access_traversal_tag, Incrementable, const Incrementable&)
-else
-    return iterator-category(
-         iterator_traversal<Incrementable>::type,
-         Incrementable, const Incrementable&)
-
-
-
[Note: implementers are encouraged to provide an implementation of
-
operator- and a difference_type that avoids overflows in -the cases where std::numeric_limits<Incrementable>::is_specialized -is true.]
-
-
-
-

counting_iterator requirements

-

The Incrementable argument shall be Copy Constructible and Assignable.

-

If iterator_category is convertible to forward_iterator_tag -or forward_traversal_tag, the following must be well-formed:

-
-Incrementable i, j;
-++i;         // pre-increment
-i == j;      // operator equal
-
-

If iterator_category is convertible to -bidirectional_iterator_tag or bidirectional_traversal_tag, -the following expression must also be well-formed:

-
---i
-
-

If iterator_category is convertible to -random_access_iterator_tag or random_access_traversal_tag, -the following must must also be valid:

-
-counting_iterator::difference_type n;
-i += n;
-n = i - j;
-i < j;
-
-
-
-

counting_iterator models

-

Specializations of counting_iterator model Readable Lvalue -Iterator. In addition, they model the concepts corresponding to the -iterator tags to which their iterator_category is convertible. -Also, if CategoryOrTraversal is not use_default then -counting_iterator models the concept corresponding to the iterator -tag CategoryOrTraversal. Otherwise, if -numeric_limits<Incrementable>::is_specialized, then -counting_iterator models Random Access Traversal Iterator. -Otherwise, counting_iterator models the same iterator traversal -concepts modeled by Incrementable.

-

counting_iterator<X,C1,D1> is interoperable with -counting_iterator<Y,C2,D2> if and only if X is -interoperable with Y.

-
-
-

counting_iterator operations

-

In addition to the operations required by the concepts modeled by -counting_iterator, counting_iterator provides the following -operations.

-

counting_iterator();

- --- - - - - - -
Requires:Incrementable is Default Constructible.
Effects:Default construct the member m_inc.
-

counting_iterator(counting_iterator const& rhs);

- --- - - - -
Effects:Construct member m_inc from rhs.m_inc.
-

explicit counting_iterator(Incrementable x);

- --- - - - -
Effects:Construct member m_inc from x.
-

reference operator*() const;

- --- - - - -
Returns:m_inc
-

counting_iterator& operator++();

- --- - - - - - -
Effects:++m_inc
Returns:*this
-

counting_iterator& operator--();

- --- - - - - - -
Effects:--m_inc
Returns:*this
-

Incrementable const& base() const;

- --- - - - -
Returns:m_inc
- - - -
-template <class Incrementable>
-counting_iterator<Incrementable> make_counting_iterator(Incrementable x);
-
- --- - - - -
Returns:An instance of counting_iterator<Incrementable> -with current constructed from x.
- - - -
-
-

Example

-

This example fills an array with numbers and a second array with -pointers into the first array, using counting_iterator for both -tasks. Finally indirect_iterator is used to print out the numbers -into the first array via indirection through the second array.

-
-int N = 7;
-std::vector<int> numbers;
-typedef std::vector<int>::iterator n_iter;
-std::copy(boost::counting_iterator<int>(0),
-         boost::counting_iterator<int>(N),
-         std::back_inserter(numbers));
-
-std::vector<std::vector<int>::iterator> pointers;
-std::copy(boost::make_counting_iterator(numbers.begin()),
-          boost::make_counting_iterator(numbers.end()),
-          std::back_inserter(pointers));
-
-std::cout << "indirectly printing out the numbers from 0 to "
-          << N << std::endl;
-std::copy(boost::make_indirect_iterator(pointers.begin()),
-          boost::make_indirect_iterator(pointers.end()),
-          std::ostream_iterator<int>(std::cout, " "));
-std::cout << std::endl;
-
-

The output is:

-
-indirectly printing out the numbers from 0 to 7
-0 1 2 3 4 5 6
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/counting_iterator.pdf b/doc/counting_iterator.pdf deleted file mode 100755 index 21b2d96..0000000 Binary files a/doc/counting_iterator.pdf and /dev/null differ diff --git a/doc/counting_iterator.rst b/doc/counting_iterator.rst deleted file mode 100644 index ff7da3c..0000000 --- a/doc/counting_iterator.rst +++ /dev/null @@ -1,43 +0,0 @@ -.. 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) - -+++++++++++++++++++ - Counting Iterator -+++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: How would you fill up a vector with the numbers zero - through one hundred using ``std::copy()``? The only iterator - operation missing from builtin integer types is an - ``operator*()`` that returns the current value of the integer. - The counting iterator adaptor adds this crucial piece of - functionality to whatever type it wraps. One can use the - counting iterator adaptor not only with integer types, but with - any incrementable type. - - .. include:: counting_iterator_abstract.rst - -.. contents:: Table of Contents - -``counting_iterator`` synopsis -.............................. - -.. include:: counting_iterator_ref.rst -.. include:: make_counting_iterator.rst - -.. include:: counting_iterator_eg.rst - -.. _iterator-category: iterator_facade.html#iterator-category -.. |iterator-category| replace:: *iterator-category* diff --git a/doc/counting_iterator_abstract.rst b/doc/counting_iterator_abstract.rst deleted file mode 100644 index 117b94e..0000000 --- a/doc/counting_iterator_abstract.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. 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) - -``counting_iterator`` adapts an object by adding an ``operator*`` that -returns the current value of the object. All other iterator operations -are forwarded to the adapted object. - diff --git a/doc/counting_iterator_eg.rst b/doc/counting_iterator_eg.rst deleted file mode 100644 index b64562d..0000000 --- a/doc/counting_iterator_eg.rst +++ /dev/null @@ -1,43 +0,0 @@ -.. 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) - -Example -....... - -This example fills an array with numbers and a second array with -pointers into the first array, using ``counting_iterator`` for both -tasks. Finally ``indirect_iterator`` is used to print out the numbers -into the first array via indirection through the second array. - -:: - - int N = 7; - std::vector numbers; - typedef std::vector::iterator n_iter; - std::copy(boost::counting_iterator(0), - boost::counting_iterator(N), - std::back_inserter(numbers)); - - std::vector::iterator> pointers; - std::copy(boost::make_counting_iterator(numbers.begin()), - boost::make_counting_iterator(numbers.end()), - std::back_inserter(pointers)); - - std::cout << "indirectly printing out the numbers from 0 to " - << N << std::endl; - std::copy(boost::make_indirect_iterator(pointers.begin()), - boost::make_indirect_iterator(pointers.end()), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - -The output is:: - - indirectly printing out the numbers from 0 to 7 - 0 1 2 3 4 5 6 - -The source code for this example can be found `here`__. - -__ ../example/counting_iterator_example.cpp - diff --git a/doc/counting_iterator_ref.rst b/doc/counting_iterator_ref.rst deleted file mode 100644 index 1c5fd1c..0000000 --- a/doc/counting_iterator_ref.rst +++ /dev/null @@ -1,149 +0,0 @@ -.. 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) - -:: - - template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default - > - class counting_iterator - { - public: - typedef Incrementable value_type; - typedef const Incrementable& reference; - typedef const Incrementable* pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - - counting_iterator(); - counting_iterator(counting_iterator const& rhs); - explicit counting_iterator(Incrementable x); - Incrementable const& base() const; - reference operator*() const; - counting_iterator& operator++(); - counting_iterator& operator--(); - private: - Incrementable m_inc; // exposition - }; - - -If the ``Difference`` argument is ``use_default`` then -``difference_type`` is an unspecified signed integral -type. Otherwise ``difference_type`` is ``Difference``. - -``iterator_category`` is determined according to the following -algorithm: - -.. parsed-literal:: - - if (CategoryOrTraversal is not use_default) - return CategoryOrTraversal - else if (numeric_limits::is_specialized) - return |iterator-category|_\ ( - random_access_traversal_tag, Incrementable, const Incrementable&) - else - return |iterator-category|_\ ( - iterator_traversal::type, - Incrementable, const Incrementable&) - -[*Note:* implementers are encouraged to provide an implementation of - ``operator-`` and a ``difference_type`` that avoids overflows in - the cases where ``std::numeric_limits::is_specialized`` - is true.] - -``counting_iterator`` requirements -.................................. - -The ``Incrementable`` argument shall be Copy Constructible and Assignable. - -If ``iterator_category`` is convertible to ``forward_iterator_tag`` -or ``forward_traversal_tag``, the following must be well-formed:: - - Incrementable i, j; - ++i; // pre-increment - i == j; // operator equal - - -If ``iterator_category`` is convertible to -``bidirectional_iterator_tag`` or ``bidirectional_traversal_tag``, -the following expression must also be well-formed:: - - --i - -If ``iterator_category`` is convertible to -``random_access_iterator_tag`` or ``random_access_traversal_tag``, -the following must must also be valid:: - - counting_iterator::difference_type n; - i += n; - n = i - j; - i < j; - -``counting_iterator`` models -............................ - -Specializations of ``counting_iterator`` model Readable Lvalue -Iterator. In addition, they model the concepts corresponding to the -iterator tags to which their ``iterator_category`` is convertible. -Also, if ``CategoryOrTraversal`` is not ``use_default`` then -``counting_iterator`` models the concept corresponding to the iterator -tag ``CategoryOrTraversal``. Otherwise, if -``numeric_limits::is_specialized``, then -``counting_iterator`` models Random Access Traversal Iterator. -Otherwise, ``counting_iterator`` models the same iterator traversal -concepts modeled by ``Incrementable``. - -``counting_iterator`` is interoperable with -``counting_iterator`` if and only if ``X`` is -interoperable with ``Y``. - - - -``counting_iterator`` operations -................................ - -In addition to the operations required by the concepts modeled by -``counting_iterator``, ``counting_iterator`` provides the following -operations. - - -``counting_iterator();`` - -:Requires: ``Incrementable`` is Default Constructible. -:Effects: Default construct the member ``m_inc``. - - -``counting_iterator(counting_iterator const& rhs);`` - -:Effects: Construct member ``m_inc`` from ``rhs.m_inc``. - - - -``explicit counting_iterator(Incrementable x);`` - -:Effects: Construct member ``m_inc`` from ``x``. - - -``reference operator*() const;`` - -:Returns: ``m_inc`` - - -``counting_iterator& operator++();`` - -:Effects: ``++m_inc`` -:Returns: ``*this`` - - -``counting_iterator& operator--();`` - -:Effects: ``--m_inc`` -:Returns: ``*this`` - - -``Incrementable const& base() const;`` - -:Returns: ``m_inc`` diff --git a/doc/default.css b/doc/default.css deleted file mode 100644 index 8c1e342..0000000 --- a/doc/default.css +++ /dev/null @@ -1,226 +0,0 @@ -/* -:Author: David Goodger -:Contact: goodger@users.sourceforge.net -:date: $Date$ -:version: $Revision$ -:copyright: This stylesheet has been placed in the public domain. - -boostinspect:nolicense - -Default cascading style sheet for the HTML output of Docutils. -*/ - -.first { - margin-top: 0 } - -.last { - margin-bottom: 0 } - -a.toc-backref { - text-decoration: none ; - color: black } - -dd { - margin-bottom: 0.5em } - -div.abstract { - margin: 2em 5em } - -div.abstract p.topic-title { - font-weight: bold ; - text-align: center } - -div.attention, div.caution, div.danger, div.error, div.hint, -div.important, div.note, div.tip, div.warning, div.admonition { - margin: 2em ; - border: medium outset ; - padding: 1em } - -div.attention p.admonition-title, div.caution p.admonition-title, -div.danger p.admonition-title, div.error p.admonition-title, -div.warning p.admonition-title { - color: red ; - font-weight: bold ; - font-family: sans-serif } - -div.hint p.admonition-title, div.important p.admonition-title, -div.note p.admonition-title, div.tip p.admonition-title, -div.admonition p.admonition-title { - font-weight: bold ; - font-family: sans-serif } - -div.dedication { - margin: 2em 5em ; - text-align: center ; - font-style: italic } - -div.dedication p.topic-title { - font-weight: bold ; - font-style: normal } - -div.figure { - margin-left: 2em } - -div.footer, div.header { - font-size: smaller } - -div.sidebar { - margin-left: 1em ; - border: medium outset ; - padding: 0em 1em ; - background-color: #ffffee ; - width: 40% ; - float: right ; - clear: right } - -div.sidebar p.rubric { - font-family: sans-serif ; - font-size: medium } - -div.system-messages { - margin: 5em } - -div.system-messages h1 { - color: red } - -div.system-message { - border: medium outset ; - padding: 1em } - -div.system-message p.system-message-title { - color: red ; - font-weight: bold } - -div.topic { - margin: 2em } - -h1.title { - text-align: center } - -h2.subtitle { - text-align: center } - -hr { - width: 75% } - -ol.simple, ul.simple { - margin-bottom: 1em } - -ol.arabic { - list-style: decimal } - -ol.loweralpha { - list-style: lower-alpha } - -ol.upperalpha { - list-style: upper-alpha } - -ol.lowerroman { - list-style: lower-roman } - -ol.upperroman { - list-style: upper-roman } - -p.attribution { - text-align: right ; - margin-left: 50% } - -p.caption { - font-style: italic } - -p.credits { - font-style: italic ; - font-size: smaller } - -p.label { - white-space: nowrap } - -p.rubric { - font-weight: bold ; - font-size: larger ; - color: maroon ; - text-align: center } - -p.sidebar-title { - font-family: sans-serif ; - font-weight: bold ; - font-size: larger } - -p.sidebar-subtitle { - font-family: sans-serif ; - font-weight: bold } - -p.topic-title { - font-weight: bold } - -pre.address { - margin-bottom: 0 ; - margin-top: 0 ; - font-family: serif ; - font-size: 100% } - -pre.line-block { - font-family: serif ; - font-size: 100% } - -pre.literal-block, pre.doctest-block { - margin-left: 2em ; - margin-right: 2em ; - background-color: #eeeeee } - -span.classifier { - font-family: sans-serif ; - font-style: oblique } - -span.classifier-delimiter { - font-family: sans-serif ; - font-weight: bold } - -span.interpreted { - font-family: sans-serif } - -span.option { - white-space: nowrap } - -span.option-argument { - font-style: italic } - -span.pre { - white-space: pre } - -span.problematic { - color: red } - -table { - margin-top: 0.5em ; - margin-bottom: 0.5em } - -table.citation { - border-left: solid thin gray ; - padding-left: 0.5ex } - -table.docinfo { - margin: 2em 4em } - -table.footnote { - border-left: solid thin black ; - padding-left: 0.5ex } - -td, th { - padding-left: 0.5em ; - padding-right: 0.5em ; - vertical-align: top } - -th.docinfo-name, th.field-name { - font-weight: bold ; - text-align: left ; - white-space: nowrap } - -h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { - font-size: 100% } - -tt { - background-color: #eeeeee } - -ul.auto-toc { - list-style-type: none } diff --git a/doc/docutils.sty b/doc/docutils.sty deleted file mode 100755 index a6fce3f..0000000 --- a/doc/docutils.sty +++ /dev/null @@ -1,54 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%% docutils.sty: A style for docutils latex output %%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% -%% o author: Alexander Schmolck (a.schmolck@gmx.net) -%% o created: 2002-07-07 10:50:31+00:40 -%% o last modified: $Date: 2004/01/29 05:55:26 $ -%% o keywords: -%% o license: -%XXX titlesec -%% XXX geometry -\usepackage{graphicx} -\usepackage{latexsym} % extra symbols -\usepackage{url} % !!!: pay attention when using in other commands!!! -\usepackage{verbatim} % normal verbatim has lenght-limit -\usepackage{enumerate} % easy style choice with e.g: ``\begin{enumerate}[Ex i.]`` -\usepackage{hyperref} %href, htarget and hlink XXX: pdfauthor, pdfcreator etc. -\usepackage{xr} %XXX do we need this? -% need this to have ``fboxes`` in ``enviroments``, as well as ``verbatim``s -\usepackage{fancybox} -\usepackage{mdwtab} % better tables and arrays (fixes spacing and adds - % vertical align and multirows (m)) -\usepackage{ltxtable} % long and autoscaling tables (use X for autoscaled - % columns) -\newcommand{\transition}{\vspace{2em}\par\hrule{}\par\vspace{2em}} -\newcommand{\classifier}[1]{(\textit{#1})} -\newenvironment{topic}[1]% -{\begin{Sbox}% - \begin{minipage}{.8\textwidth}% - \protect{\large{\textbf{#1}}}\par\vspace{.5em}}% -{\end{minipage}\end{Sbox}\fbox{\TheSbox}\par\vspace{.5em}} -%XXX shadow box for warnings? -\newenvironment{admonition}[1]% -{\begin{center}% - \begin{Sbox}% - \begin{minipage}{.9\textwidth}% - \protect{\textsc{#1}}\par\vspace{.2em}}% -{\end{minipage}\end{Sbox}\fbox{\TheSbox}\par\vspace{.5em}\end{center}} - -\newenvironment{doctest}% -{\VerbatimEnvironment - \begin{Verbatim}}% -{\end{Verbatim}} -% {% -% \begin{Sbox}% -% \begin{minipage}{.8\textwidth}% -% \protect{\large{\textsc{#1}}\par\vspace{.5em}}}% -% {\end{minipage}\end{Sbox}\fbox{\TheSbox}\par\vspace{.5em}} -%{\end{minipage}\end{Sbox}\fbox{\TheSbox}} - - -%% just a piece of example code -% \newcommand{\vitem}% -% {\SaveVerb[{\item[\UseVerb{\MyTemp}]}]{\MyTemp}} diff --git a/doc/facade-and-adaptor.html b/doc/facade-and-adaptor.html deleted file mode 100755 index d2199e6..0000000 --- a/doc/facade-and-adaptor.html +++ /dev/null @@ -1,2992 +0,0 @@ - - - - - - -Iterator Facade and Adaptor - - - - - - -
-

Iterator Facade and Adaptor

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
Organization:Boost Consulting, Indiana University Open Systems -Lab, Zephyr Associates, Inc.
Date:2004-11-01
Number:This is a revised version of N1530=03-0113, which was -accepted for Technical Report 1 by the C++ standard -committee's library working group.
- - - - - --- - - - -
copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- --- - - - -
abstract:We propose a set of class templates that help programmers -build standard-conforming iterators, both from scratch and -by adapting other iterators.
-
-

Table of Contents

- -
-
-

Motivation

-

Iterators play an important role in modern C++ programming. The -iterator is the central abstraction of the algorithms of the Standard -Library, allowing algorithms to be re-used in in a wide variety of -contexts. The C++ Standard Library contains a wide variety of useful -iterators. Every one of the standard containers comes with constant -and mutable iterators [2], and also reverse versions of those -same iterators which traverse the container in the opposite direction. -The Standard also supplies istream_iterator and -ostream_iterator for reading from and writing to streams, -insert_iterator, front_insert_iterator and -back_insert_iterator for inserting elements into containers, and -raw_storage_iterator for initializing raw memory [7].

-

Despite the many iterators supplied by the Standard Library, obvious -and useful iterators are missing, and creating new iterator types is -still a common task for C++ programmers. The literature documents -several of these, for example line_iterator [3] and Constant_iterator -[9]. The iterator abstraction is so powerful that we expect -programmers will always need to invent new iterator types.

-

Although it is easy to create iterators that almost conform to the -standard, the iterator requirements contain subtleties which can make -creating an iterator which actually conforms quite difficult. -Further, the iterator interface is rich, containing many operators -that are technically redundant and tedious to implement. To automate -the repetitive work of constructing iterators, we propose -iterator_facade, an iterator base class template which provides -the rich interface of standard iterators and delegates its -implementation to member functions of the derived class. In addition -to reducing the amount of code necessary to create an iterator, the -iterator_facade also provides compile-time error detection. -Iterator implementation mistakes that often go unnoticed are turned -into compile-time errors because the derived class implementation must -match the expectations of the iterator_facade.

-

A common pattern of iterator construction is the adaptation of one -iterator to form a new one. The functionality of an iterator is -composed of four orthogonal aspects: traversal, indirection, equality -comparison and distance measurement. Adapting an old iterator to -create a new one often saves work because one can reuse one aspect of -functionality while redefining the other. For example, the Standard -provides reverse_iterator, which adapts any Bidirectional Iterator -by inverting its direction of traversal. As with plain iterators, -iterator adaptors defined outside the Standard have become commonplace -in the literature:

-
    -
  • Checked iter[13] adds bounds-checking to an existing iterator.
  • -
  • The iterators of the View Template Library[14], which adapts -containers, are themselves adaptors over the underlying iterators.
  • -
  • Smart iterators [5] adapt an iterator's dereferencing behavior by -applying a function object to the object being referenced and -returning the result.
  • -
  • Custom iterators [4], in which a variety of adaptor types are enumerated.
  • -
  • Compound iterators [1], which access a slice out of a container of containers.
  • -
  • Several iterator adaptors from the MTL [12]. The MTL contains a -strided iterator, where each call to operator++() moves the -iterator ahead by some constant factor, and a scaled iterator, which -multiplies the dereferenced value by some constant.
  • -
- - - - - -
[1]We use the term concept to mean a set of requirements -that a type must satisfy to be used with a particular template -parameter.
- - - - - -
[2]The term mutable iterator refers to iterators over objects that -can be changed by assigning to the dereferenced iterator, while -constant iterator refers to iterators over objects that cannot be -modified.
-

To fulfill the need for constructing adaptors, we propose the -iterator_adaptor class template. Instantiations of -iterator_adaptor serve as a base classes for new iterators, -providing the default behavior of forwarding all operations to the -underlying iterator. The user can selectively replace these features -in the derived iterator class. This proposal also includes a number -of more specialized adaptors, such as the transform_iterator that -applies some user-specified function during the dereference of the -iterator.

-
-
-

Impact on the Standard

-

This proposal is purely an addition to the C++ standard library. -However, note that this proposal relies on the proposal for New -Iterator Concepts.

-
-
-

Design

-
-

Iterator Concepts

-

This proposal is formulated in terms of the new iterator concepts -as proposed in n1550, since user-defined and especially adapted -iterators suffer from the well known categorization problems that are -inherent to the current iterator categories.

-

This proposal does not strictly depend on proposal n1550, as there -is a direct mapping between new and old categories. This proposal -could be reformulated using this mapping if n1550 was not accepted.

-
-
-

Interoperability

-

The question of iterator interoperability is poorly addressed in the -current standard. There are currently two defect reports that are -concerned with interoperability issues.

-

Issue 179 concerns the fact that mutable container iterator types -are only required to be convertible to the corresponding constant -iterator types, but objects of these types are not required to -interoperate in comparison or subtraction expressions. This situation -is tedious in practice and out of line with the way built in types -work. This proposal implements the proposed resolution to issue -179, as most standard library implementations do nowadays. In other -words, if an iterator type A has an implicit or user defined -conversion to an iterator type B, the iterator types are interoperable -and the usual set of operators are available.

-

Issue 280 concerns the current lack of interoperability between -reverse iterator types. The proposed new reverse_iterator template -fixes the issues raised in 280. It provides the desired -interoperability without introducing unwanted overloads.

-
-
-

Iterator Facade

- - - - - -

While the iterator interface is rich, there is a core subset of the -interface that is necessary for all the functionality. We have -identified the following core behaviors for iterators:

-
    -
  • dereferencing
  • -
  • incrementing
  • -
  • decrementing
  • -
  • equality comparison
  • -
  • random-access motion
  • -
  • distance measurement
  • -
-

In addition to the behaviors listed above, the core interface elements -include the associated types exposed through iterator traits: -value_type, reference, difference_type, and -iterator_category.

-

Iterator facade uses the Curiously Recurring Template -Pattern (CRTP) [Cop95] so that the user can specify the behavior -of iterator_facade in a derived class. Former designs used -policy objects to specify the behavior, but that approach was -discarded for several reasons:

-
-
    -
  1. the creation and eventual copying of the policy object may create -overhead that can be avoided with the current approach.
  2. -
  3. The policy object approach does not allow for custom constructors -on the created iterator types, an essential feature if -iterator_facade should be used in other library -implementations.
  4. -
  5. Without the use of CRTP, the standard requirement that an -iterator's operator++ returns the iterator type itself -would mean that all iterators built with the library would -have to be specializations of iterator_facade<...>, rather -than something more descriptive like -indirect_iterator<T*>. Cumbersome type generator -metafunctions would be needed to build new parameterized -iterators, and a separate iterator_adaptor layer would be -impossible.
  6. -
-
-
-

Usage

-

The user of iterator_facade derives his iterator class from a -specialization of iterator_facade and passes the derived -iterator class as iterator_facade's first template parameter. -The order of the other template parameters have been carefully -chosen to take advantage of useful defaults. For example, when -defining a constant lvalue iterator, the user can pass a -const-qualified version of the iterator's value_type as -iterator_facade's Value parameter and omit the -Reference parameter which follows.

-

The derived iterator class must define member functions implementing -the iterator's core behaviors. The following table describes -expressions which are required to be valid depending on the category -of the derived iterator type. These member functions are described -briefly below and in more detail in the iterator facade -requirements.

-
- ---- - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionEffects
i.dereference()Access the value referred to
i.equal(j)Compare for equality with j
i.increment()Advance by one position
i.decrement()Retreat by one position
i.advance(n)Advance by n positions
i.distance_to(j)Measure the distance to j
-
- -

In addition to implementing the core interface functions, an iterator -derived from iterator_facade typically defines several -constructors. To model any of the standard iterator concepts, the -iterator must at least have a copy constructor. Also, if the iterator -type X is meant to be automatically interoperate with another -iterator type Y (as with constant and mutable iterators) then -there must be an implicit conversion from X to Y or from Y -to X (but not both), typically implemented as a conversion -constructor. Finally, if the iterator is to model Forward Traversal -Iterator or a more-refined iterator concept, a default constructor is -required.

-
-
-

Iterator Core Access

-

iterator_facade and the operator implementations need to be able -to access the core member functions in the derived class. Making the -core member functions public would expose an implementation detail to -the user. The design used here ensures that implementation details do -not appear in the public interface of the derived iterator type.

-

Preventing direct access to the core member functions has two -advantages. First, there is no possibility for the user to accidently -use a member function of the iterator when a member of the value_type -was intended. This has been an issue with smart pointer -implementations in the past. The second and main advantage is that -library implementers can freely exchange a hand-rolled iterator -implementation for one based on iterator_facade without fear of -breaking code that was accessing the public core member functions -directly.

-

In a naive implementation, keeping the derived class' core member -functions private would require it to grant friendship to -iterator_facade and each of the seven operators. In order to -reduce the burden of limiting access, iterator_core_access is -provided, a class that acts as a gateway to the core member functions -in the derived iterator class. The author of the derived class only -needs to grant friendship to iterator_core_access to make his core -member functions available to the library.

- - -

iterator_core_access will be typically implemented as an empty -class containing only private static member functions which invoke the -iterator core member functions. There is, however, no need to -standardize the gateway protocol. Note that even if -iterator_core_access used public member functions it would not -open a safety loophole, as every core member function preserves the -invariants of the iterator.

-
-
-

operator[]

-

The indexing operator for a generalized iterator presents special -challenges. A random access iterator's operator[] is only -required to return something convertible to its value_type. -Requiring that it return an lvalue would rule out currently-legal -random-access iterators which hold the referenced value in a data -member (e.g. counting_iterator), because *(p+n) is a reference -into the temporary iterator p+n, which is destroyed when -operator[] returns.

-

Writable iterators built with iterator_facade implement the -semantics required by the preferred resolution to issue 299 and -adopted by proposal n1550: the result of p[n] is an object -convertible to the iterator's value_type, and p[n] = x is -equivalent to *(p + n) = x (Note: This result object may be -implemented as a proxy containing a copy of p+n). This approach -will work properly for any random-access iterator regardless of the -other details of its implementation. A user who knows more about -the implementation of her iterator is free to implement an -operator[] that returns an lvalue in the derived iterator -class; it will hide the one supplied by iterator_facade from -clients of her iterator.

-
-
-

operator->

-

The reference type of a readable iterator (and today's input -iterator) need not in fact be a reference, so long as it is -convertible to the iterator's value_type. When the value_type -is a class, however, it must still be possible to access members -through operator->. Therefore, an iterator whose reference -type is not in fact a reference must return a proxy containing a copy -of the referenced value from its operator->.

-

The return types for iterator_facade's operator-> and -operator[] are not explicitly specified. Instead, those types -are described in terms of a set of requirements, which must be -satisfied by the iterator_facade implementation.

- - - - - -
[Cop95][Coplien, 1995] Coplien, J., Curiously Recurring Template -Patterns, C++ Report, February 1995, pp. 24-27.
-
-
-
-

Iterator Adaptor

- - - - - -

The iterator_adaptor class template adapts some Base [3] -type to create a new iterator. Instantiations of iterator_adaptor -are derived from a corresponding instantiation of iterator_facade -and implement the core behaviors in terms of the Base type. In -essence, iterator_adaptor merely forwards all operations to an -instance of the Base type, which it stores as a member.

- - - - - -
[3]The term "Base" here does not refer to a base class and is -not meant to imply the use of derivation. We have followed the lead -of the standard library, which provides a base() function to access -the underlying iterator object of a reverse_iterator adaptor.
-

The user of iterator_adaptor creates a class derived from an -instantiation of iterator_adaptor and then selectively -redefines some of the core member functions described in the -iterator_facade core requirements table. The Base type need -not meet the full requirements for an iterator; it need only -support the operations used by the core interface functions of -iterator_adaptor that have not been redefined in the user's -derived class.

-

Several of the template parameters of iterator_adaptor default -to use_default. This allows the -user to make use of a default parameter even when she wants to -specify a parameter later in the parameter list. Also, the -defaults for the corresponding associated types are somewhat -complicated, so metaprogramming is required to compute them, and -use_default can help to simplify the implementation. Finally, -the identity of the use_default type is not left unspecified -because specification helps to highlight that the Reference -template parameter may not always be identical to the iterator's -reference type, and will keep users from making mistakes based on -that assumption.

-
-
-

Specialized Adaptors

-

This proposal also contains several examples of specialized adaptors -which were easily implemented using iterator_adaptor:

-
    -
  • indirect_iterator, which iterates over iterators, pointers, -or smart pointers and applies an extra level of dereferencing.
  • -
  • A new reverse_iterator, which inverts the direction of a Base -iterator's motion, while allowing adapted constant and mutable -iterators to interact in the expected ways (unlike those in most -implementations of C++98).
  • -
  • transform_iterator, which applies a user-defined function object -to the underlying values when dereferenced.
  • -
  • filter_iterator, which provides a view of an iterator range in -which some elements of the underlying range are skipped.
  • -
-
    -
  • counting_iterator, which adapts any incrementable type -(e.g. integers, iterators) so that incrementing/decrementing the -adapted iterator and dereferencing it produces successive values of -the Base type.
  • -
  • function_output_iterator, which makes it easier to create custom -output iterators.
  • -
-

Based on examples in the Boost library, users have generated many new -adaptors, among them a permutation adaptor which applies some -permutation to a random access iterator, and a strided adaptor, which -adapts a random access iterator by multiplying its unit of motion by a -constant factor. In addition, the Boost Graph Library (BGL) uses -iterator adaptors to adapt other graph libraries, such as LEDA [10] -and Stanford GraphBase [8], to the BGL interface (which requires C++ -Standard compliant iterators).

-
-
-
-

Proposed Text

-
-

Header <iterator_helper> synopsis [lib.iterator.helper.synopsis]

-
-struct use_default;
-
-struct iterator_core_access { /* implementation detail */ };
-
-template <
-    class Derived
-  , class Value
-  , class CategoryOrTraversal
-  , class Reference  = Value&
-  , class Difference = ptrdiff_t
->
-class iterator_facade;
-
-template <
-    class Derived
-  , class Base
-  , class Value      = use_default
-  , class CategoryOrTraversal  = use_default
-  , class Reference  = use_default
-  , class Difference = use_default
->
-class iterator_adaptor;
-
-template <
-    class Iterator
-  , class Value = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference = use_default
-  , class Difference = use_default
->
-class indirect_iterator;
-
-template <class Dereferenceable>
-struct pointee;
-
-template <class Dereferenceable>
-struct indirect_reference;
-
-template <class Iterator>
-class reverse_iterator;
-
-template <
-    class UnaryFunction
-  , class Iterator
-  , class Reference = use_default
-  , class Value = use_default
->
-class transform_iterator;
-
-template <class Predicate, class Iterator>
-class filter_iterator;
-
-template <
-    class Incrementable
-  , class CategoryOrTraversal  = use_default
-  , class Difference = use_default
->
-class counting_iterator;
-
-template <class UnaryFunction>
-class function_output_iterator;
-
-
-
-

Iterator facade [lib.iterator.facade]

- - - -

iterator_facade is a base class template that implements the -interface of standard iterators in terms of a few core functions -and associated types, to be supplied by a derived iterator class.

-
-

Class template iterator_facade

- - - - - -
-template <
-    class Derived
-  , class Value
-  , class CategoryOrTraversal
-  , class Reference  = Value&
-  , class Difference = ptrdiff_t
->
-class iterator_facade {
- public:
-    typedef remove_const<Value>::type value_type;
-    typedef Reference reference;
-    typedef Value* pointer;
-    typedef Difference difference_type;
-    typedef /* see below */ iterator_category;
-
-    reference operator*() const;
-    /* see below */ operator->() const;
-    /* see below */ operator[](difference_type n) const;
-    Derived& operator++();
-    Derived operator++(int);
-    Derived& operator--();
-    Derived operator--(int);
-    Derived& operator+=(difference_type n);
-    Derived& operator-=(difference_type n);
-    Derived operator-(difference_type n) const;
- protected:
-    typedef iterator_facade iterator_facade_;
-};
-
-// Comparison operators
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator difference
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-/* see below */
-operator-(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-          iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator addition
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
-

The iterator_category member of iterator_facade is

-
-iterator-category(CategoryOrTraversal, value_type, reference)
-
-

where iterator-category is defined as follows:

-
-iterator-category(C,R,V) :=
-   if (C is convertible to std::input_iterator_tag
-       || C is convertible to std::output_iterator_tag
-   )
-       return C
-
-   else if (C is not convertible to incrementable_traversal_tag)
-       the program is ill-formed
-
-   else return a type X satisfying the following two constraints:
-
-      1. X is convertible to X1, and not to any more-derived
-         type, where X1 is defined by:
-
-           if (R is a reference type
-               && C is convertible to forward_traversal_tag)
-           {
-               if (C is convertible to random_access_traversal_tag)
-                   X1 = random_access_iterator_tag
-               else if (C is convertible to bidirectional_traversal_tag)
-                   X1 = bidirectional_iterator_tag
-               else
-                   X1 = forward_iterator_tag
-           }
-           else
-           {
-               if (C is convertible to single_pass_traversal_tag
-                   && R is convertible to V)
-                   X1 = input_iterator_tag
-               else
-                   X1 = C
-           }
-
-      2. category-to-traversal(X) is convertible to the most
-         derived traversal tag type to which X is also
-         convertible, and not to any more-derived traversal tag
-         type.
-
-

[Note: the intention is to allow iterator_category to be one of -the five original category tags when convertibility to one of the -traversal tags would add no information]

- - - -

The enable_if_interoperable template used above is for exposition -purposes. The member operators should only be in an overload set -provided the derived types Dr1 and Dr2 are interoperable, -meaning that at least one of the types is convertible to the other. The -enable_if_interoperable approach uses SFINAE to take the operators -out of the overload set when the types are not interoperable. -The operators should behave as-if enable_if_interoperable -were defined to be:

-
-template <bool, typename> enable_if_interoperable_impl
-{};
-
-template <typename T> enable_if_interoperable_impl<true,T>
-{ typedef T type; };
-
-template<typename Dr1, typename Dr2, typename T>
-struct enable_if_interoperable
-  : enable_if_interoperable_impl<
-        is_convertible<Dr1,Dr2>::value || is_convertible<Dr2,Dr1>::value
-      , T
-    >
-{};
-
-
-
-

iterator_facade Requirements

-

The following table describes the typical valid expressions on -iterator_facade's Derived parameter, depending on the -iterator concept(s) it will model. The operations in the first -column must be made accessible to member functions of class -iterator_core_access. In addition, -static_cast<Derived*>(iterator_facade*) shall be well-formed.

-

In the table below, F is iterator_facade<X,V,C,R,D>, a is an -object of type X, b and c are objects of type const X, -n is an object of F::difference_type, y is a constant -object of a single pass iterator type interoperable with X, and z -is a constant object of a random access traversal iterator type -interoperable with X.

-
-

iterator_facade Core Operations

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeAssertion/NoteUsed to implement Iterator -Concept(s)
c.dereference()F::reference Readable Iterator, Writable -Iterator
c.equal(y)convertible to booltrue iff c and y -refer to the same -position.Single Pass Iterator
a.increment()unused Incrementable Iterator
a.decrement()unused Bidirectional Traversal -Iterator
a.advance(n)unused Random Access Traversal -Iterator
c.distance_to(z)convertible to -F::difference_typeequivalent to -distance(c, X(z)).Random Access Traversal -Iterator
-
-
-
-

iterator_facade operations

-

The operations in this section are described in terms of operations on -the core interface of Derived which may be inaccessible -(i.e. private). The implementation should access these operations -through member functions of class iterator_core_access.

-

reference operator*() const;

- --- - - - -
Returns:static_cast<Derived const*>(this)->dereference()
-

operator->() const; (see below)

- --- - - - -
Returns:

If reference is a reference type, an object -of type pointer equal to:

-
-&static_cast<Derived const*>(this)->dereference()
-
-

Otherwise returns an object of unspecified type such that, -(*static_cast<Derived const*>(this))->m is equivalent to (w = **static_cast<Derived const*>(this), -w.m) for some temporary object w of type value_type.

-
-

unspecified operator[](difference_type n) const;

- --- - - - -
Returns:an object convertible to value_type. For constant -objects v of type value_type, and n of type -difference_type, (*this)[n] = v is equivalent to -*(*this + n) = v, and static_cast<value_type -const&>((*this)[n]) is equivalent to -static_cast<value_type const&>(*(*this + n))
-

Derived& operator++();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->increment();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator++(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-++*this;
-return tmp;
-
-
-

Derived& operator--();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->decrement();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator--(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
---*this;
-return tmp;
-
-
-

Derived& operator+=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(n);
-return *static_cast<Derived*>(this);
-
-
-

Derived& operator-=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(-n);
-return *static_cast<Derived*>(this);
-
-
-

Derived operator-(difference_type n) const;

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp -= n;
-
-
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp += n;
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).equal((Dr2 const&)rhs).

-
-
Otherwise,
-

((Dr2 const&)rhs).equal((Dr1 const&)lhs).

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

!((Dr1 const&)lhs).equal((Dr2 const&)rhs).

-
-
Otherwise,
-

!((Dr2 const&)rhs).equal((Dr1 const&)lhs).

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) < 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) > 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) <= 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) >= 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) > 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) < 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) >= 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) <= 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,difference>::type
-operator -(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - - - -
Return Type:

if is_convertible<Dr2,Dr1>::value

-
-
-
then
-

difference shall be -iterator_traits<Dr1>::difference_type.

-
-
Otherwise
-

difference shall be iterator_traits<Dr2>::difference_type

-
-
-
-
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

-((Dr1 const&)lhs).distance_to((Dr2 const&)rhs).

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs).

-
-
-
-
-
-
-

Iterator adaptor [lib.iterator.adaptor]

- - - - - -

Each specialization of the iterator_adaptor class template is derived from -a specialization of iterator_facade. The core interface functions -expected by iterator_facade are implemented in terms of the -iterator_adaptor's Base template parameter. A class derived -from iterator_adaptor typically redefines some of the core -interface functions to adapt the behavior of the Base type. -Whether the derived class models any of the standard iterator concepts -depends on the operations supported by the Base type and which -core interface functions of iterator_facade are redefined in the -Derived class.

-
-

Class template iterator_adaptor

- - - - - -
-template <
-    class Derived
-  , class Base
-  , class Value               = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference           = use_default
-  , class Difference = use_default
->
-class iterator_adaptor
-  : public iterator_facade<Derived, V', C', R', D'> // see details
-{
-    friend class iterator_core_access;
- public:
-    iterator_adaptor();
-    explicit iterator_adaptor(Base const& iter);
-    typedef Base base_type;
-    Base const& base() const;
- protected:
-    typedef iterator_adaptor iterator_adaptor_;
-    Base const& base_reference() const;
-    Base& base_reference();
- private: // Core iterator interface for iterator_facade.
-    typename iterator_adaptor::reference dereference() const;
-
-    template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >
-    bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
-    void advance(typename iterator_adaptor::difference_type n);
-    void increment();
-    void decrement();
-
-    template <
-        class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >
-    typename iterator_adaptor::difference_type distance_to(
-        iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- private:
-    Base m_iterator; // exposition only
-};
-
-
-
-

iterator_adaptor requirements

-

static_cast<Derived*>(iterator_adaptor*) shall be well-formed. -The Base argument shall be Assignable and Copy Constructible.

-
-
-

iterator_adaptor base class parameters

-

The V', C', R', and D' parameters of the iterator_facade -used as a base class in the summary of iterator_adaptor -above are defined as follows:

-
-V' = if (Value is use_default)
-          return iterator_traits<Base>::value_type
-      else
-          return Value
-
-C' = if (CategoryOrTraversal is use_default)
-          return iterator_traversal<Base>::type
-      else
-          return CategoryOrTraversal
-
-R' = if (Reference is use_default)
-          if (Value is use_default)
-              return iterator_traits<Base>::reference
-          else
-              return Value&
-      else
-          return Reference
-
-D' = if (Difference is use_default)
-          return iterator_traits<Base>::difference_type
-      else
-          return Difference
-
- - - -
-
-

iterator_adaptor public operations

-

iterator_adaptor();

- --- - - - - - -
Requires:The Base type must be Default Constructible.
Returns:An instance of iterator_adaptor with -m_iterator default constructed.
-

explicit iterator_adaptor(Base const& iter);

- --- - - - -
Returns:An instance of iterator_adaptor with -m_iterator copy constructed from iter.
-

Base const& base() const;

- --- - - - -
Returns:m_iterator
-
-
-

iterator_adaptor protected member functions

-

Base const& base_reference() const;

- --- - - - -
Returns:A const reference to m_iterator.
-

Base& base_reference();

- --- - - - -
Returns:A non-const reference to m_iterator.
-
-
-

iterator_adaptor private member functions

-

typename iterator_adaptor::reference dereference() const;

- --- - - - -
Returns:*m_iterator
-
-template <
-class OtherDerived, class OtherIterator, class V, class C, class R, class D
->
-bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
- --- - - - -
Returns:m_iterator == x.base()
-

void advance(typename iterator_adaptor::difference_type n);

- --- - - - -
Effects:m_iterator += n;
-

void increment();

- --- - - - -
Effects:++m_iterator;
-

void decrement();

- --- - - - -
Effects:--m_iterator;
-
-template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
->
-typename iterator_adaptor::difference_type distance_to(
-    iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- --- - - - -
Returns:y.base() - m_iterator
-
-
-
-

Specialized adaptors [lib.iterator.special.adaptors]

-

The enable_if_convertible<X,Y>::type expression used in -this section is for exposition purposes. The converting constructors -for specialized adaptors should be only be in an overload set provided -that an object of type X is implicitly convertible to an object of -type Y. -The signatures involving enable_if_convertible should behave -as-if enable_if_convertible were defined to be:

-
-template <bool> enable_if_convertible_impl
-{};
-
-template <> enable_if_convertible_impl<true>
-{ struct type; };
-
-template<typename From, typename To>
-struct enable_if_convertible
-  : enable_if_convertible_impl<is_convertible<From,To>::value>
-{};
-
-

If an expression other than the default argument is used to supply -the value of a function parameter whose type is written in terms -of enable_if_convertible, the program is ill-formed, no -diagnostic required.

-

[Note: The enable_if_convertible approach uses SFINAE to -take the constructor out of the overload set when the types are not -implicitly convertible. -]

-
-

Indirect iterator

- - - -

indirect_iterator adapts an iterator by applying an -extra dereference inside of operator*(). For example, this -iterator adaptor makes it possible to view a container of pointers -(e.g. list<foo*>) as if it were a container of the pointed-to type -(e.g. list<foo>). indirect_iterator depends on two -auxiliary traits, pointee and indirect_reference, to -provide support for underlying iterators whose value_type is -not an iterator.

-
-

Class template pointee

- - - -
-template <class Dereferenceable>
-struct pointee
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -Dereferenceable::element_type shall be an accessible type. -Otherwise iterator_traits<Dereferenceable>::value_type shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of pointee]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-{
-    return ``Dereferenceable::element_type``
-}
-else if (``*x`` is a mutable reference to
-         std::iterator_traits<Dereferenceable>::value_type)
-{
-    return iterator_traits<Dereferenceable>::value_type
-}
-else
-{
-    return iterator_traits<Dereferenceable>::value_type const
-}
-
-
-
-

Class template indirect_reference

- - - -
-template <class Dereferenceable>
-struct indirect_reference
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -pointee<Dereferenceable>::type& shall be well-formed. -Otherwise iterator_traits<Dereferenceable>::reference shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of indirect_reference]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-    return ``pointee<Dereferenceable>::type&``
-else
-    std::iterator_traits<Dereferenceable>::reference
-
-
-
-

Class template indirect_iterator

- - - -
-template <
-    class Iterator
-  , class Value = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference = use_default
-  , class Difference = use_default
->
-class indirect_iterator
-{
- public:
-    typedef /* see below */ value_type;
-    typedef /* see below */ reference;
-    typedef /* see below */ pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    indirect_iterator();
-    indirect_iterator(Iterator x);
-
-    template <
-        class Iterator2, class Value2, class Category2
-      , class Reference2, class Difference2
-    >
-    indirect_iterator(
-        indirect_iterator<
-             Iterator2, Value2, Category2, Reference2, Difference2
-        > const& y
-      , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-    );
-
-    Iterator const& base() const;
-    reference operator*() const;
-    indirect_iterator& operator++();
-    indirect_iterator& operator--();
-private:
-   Iterator m_iterator; // exposition
-};
-
-

The member types of indirect_iterator are defined according to -the following pseudo-code, where V is -iterator_traits<Iterator>::value_type

-
-if (Value is use_default) then
-    typedef remove_const<pointee<V>::type>::type value_type;
-else
-    typedef remove_const<Value>::type value_type;
-
-if (Reference is use_default) then
-    if (Value is use_default) then
-        typedef indirect_reference<V>::type reference;
-    else
-        typedef Value& reference;
-else
-    typedef Reference reference;
-
-if (Value is use_default) then
-    typedef pointee<V>::type* pointer;
-else
-    typedef Value* pointer;
-
-if (Difference is use_default)
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-else
-    typedef Difference difference_type;
-
-if (CategoryOrTraversal is use_default)
-    typedef iterator-category (
-        iterator_traversal<Iterator>::type,``reference``,``value_type``
-    ) iterator_category;
-else
-    typedef iterator-category (
-        CategoryOrTraversal,``reference``,``value_type``
-    ) iterator_category;
-
-
-
-

indirect_iterator requirements

-

The expression *v, where v is an object of -iterator_traits<Iterator>::value_type, shall be valid -expression and convertible to reference. Iterator shall -model the traversal concept indicated by iterator_category. -Value, Reference, and Difference shall be chosen so -that value_type, reference, and difference_type meet -the requirements indicated by iterator_category.

-

[Note: there are further requirements on the -iterator_traits<Iterator>::value_type if the Value -parameter is not use_default, as implied by the algorithm for -deducing the default for the value_type member.]

-
-
-

indirect_iterator models

-

In addition to the concepts indicated by iterator_category -and by iterator_traversal<indirect_iterator>::type, a -specialization of indirect_iterator models the following -concepts, Where v is an object of -iterator_traits<Iterator>::value_type:

-
-
    -
  • Readable Iterator if reference(*v) is convertible to -value_type.
  • -
  • Writable Iterator if reference(*v) = t is a valid -expression (where t is an object of type -indirect_iterator::value_type)
  • -
  • Lvalue Iterator if reference is a reference type.
  • -
-
-

indirect_iterator<X,V1,C1,R1,D1> is interoperable with -indirect_iterator<Y,V2,C2,R2,D2> if and only if X is -interoperable with Y.

-
-
-

indirect_iterator operations

-

In addition to the operations required by the concepts described -above, specializations of indirect_iterator provide the -following operations.

-

indirect_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of indirect_iterator with -a default-constructed m_iterator.
-

indirect_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of indirect_iterator with -m_iterator copy constructed from x.
-
-template <
-    class Iterator2, class Value2, unsigned Access, class Traversal
-  , class Reference2, class Difference2
->
-indirect_iterator(
-    indirect_iterator<
-         Iterator2, Value2, Access, Traversal, Reference2, Difference2
-    > const& y
-  , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:Iterator2 is implicitly convertible to Iterator.
Effects:Constructs an instance of indirect_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:**m_iterator
-

indirect_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

indirect_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-
-
-
-

Reverse iterator

- - - -

The reverse iterator adaptor iterates through the adapted iterator -range in the opposite direction.

-
-

Class template reverse_iterator

- - - -
-template <class Iterator>
-class reverse_iterator
-{
-public:
-  typedef iterator_traits<Iterator>::value_type value_type;
-  typedef iterator_traits<Iterator>::reference reference;
-  typedef iterator_traits<Iterator>::pointer pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  reverse_iterator() {}
-  explicit reverse_iterator(Iterator x) ;
-
-  template<class OtherIterator>
-  reverse_iterator(
-      reverse_iterator<OtherIterator> const& r
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-  );
-  Iterator const& base() const;
-  reference operator*() const;
-  reverse_iterator& operator++();
-  reverse_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition
-};
-
-

If Iterator models Random Access Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -bidirectional_iterator_tag. Otherwise, iterator_category is -convertible to input_iterator_tag.

-
-
-

reverse_iterator requirements

-

Iterator must be a model of Bidirectional Traversal Iterator. The -type iterator_traits<Iterator>::reference must be the type of -*i, where i is an object of type Iterator.

-
-
-

reverse_iterator models

-

A specialization of reverse_iterator models the same iterator -traversal and iterator access concepts modeled by its Iterator -argument. In addition, it may model old iterator concepts -specified in the following table:

- ---- - - - - - - - - - - - - - - - - - - - -
If I modelsthen reverse_iterator<I> models
Readable Lvalue Iterator, -Bidirectional Traversal IteratorBidirectional Iterator
Writable Lvalue Iterator, -Bidirectional Traversal IteratorMutable Bidirectional Iterator
Readable Lvalue Iterator, -Random Access Traversal IteratorRandom Access Iterator
Writable Lvalue Iterator, -Random Access Traversal IteratorMutable Random Access Iterator
-

reverse_iterator<X> is interoperable with -reverse_iterator<Y> if and only if X is interoperable with -Y.

-
-
-

reverse_iterator operations

-

In addition to the operations required by the concepts modeled by -reverse_iterator, reverse_iterator provides the following -operations.

-

reverse_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of reverse_iterator with m_iterator -default constructed.
-

explicit reverse_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of reverse_iterator with -m_iterator copy constructed from x.
-
-template<class OtherIterator>
-reverse_iterator(
-    reverse_iterator<OtherIterator> const& r
-  , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs instance of reverse_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Effects:
-
-Iterator tmp = m_iterator;
-return *--tmp;
-
-

reverse_iterator& operator++();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-

reverse_iterator& operator--();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-
-
-
-

Transform iterator

- - - -

The transform iterator adapts an iterator by modifying the -operator* to apply a function object to the result of -dereferencing the iterator and returning the result.

-
-

Class template transform_iterator

- - - - -
-template <class UnaryFunction,
-          class Iterator,
-          class Reference = use_default,
-          class Value = use_default>
-class transform_iterator
-{
-public:
-  typedef /* see below */ value_type;
-  typedef /* see below */ reference;
-  typedef /* see below */ pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  transform_iterator();
-  transform_iterator(Iterator const& x, UnaryFunction f);
-
-  template<class F2, class I2, class R2, class V2>
-  transform_iterator(
-        transform_iterator<F2, I2, R2, V2> const& t
-      , typename enable_if_convertible<I2, Iterator>::type* = 0      // exposition only
-      , typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition only
-  );
-  UnaryFunction functor() const;
-  Iterator const& base() const;
-  reference operator*() const;
-  transform_iterator& operator++();
-  transform_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition only
-  UnaryFunction m_f;   // exposition only
-};
-
-

If Reference is use_default then the reference member of -transform_iterator is -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type. -Otherwise, reference is Reference.

-

If Value is use_default then the value_type member is -remove_cv<remove_reference<reference> >::type. Otherwise, -value_type is Value.

-

If Iterator models Readable Lvalue Iterator and if Iterator -models Random Access Traversal Iterator, then iterator_category is -convertible to random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator, then -iterator_category is convertible to -bidirectional_iterator_tag. Otherwise iterator_category is -convertible to forward_iterator_tag. If Iterator does not -model Readable Lvalue Iterator then iterator_category is -convertible to input_iterator_tag.

-
-
-

transform_iterator requirements

-

The type UnaryFunction must be Assignable, Copy Constructible, and -the expression f(*i) must be valid where f is an object of -type UnaryFunction, i is an object of type Iterator, and -where the type of f(*i) must be -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type.

-

The argument Iterator shall model Readable Iterator.

-
-
-

transform_iterator models

-

The resulting transform_iterator models the most refined of the -following that is also modeled by Iterator.

-
-
    -
  • Writable Lvalue Iterator if transform_iterator::reference is a non-const reference.
  • -
  • Readable Lvalue Iterator if transform_iterator::reference is a const reference.
  • -
  • Readable Iterator otherwise.
  • -
-
-

The transform_iterator models the most refined standard traversal -concept that is modeled by the Iterator argument.

-

If transform_iterator is a model of Readable Lvalue Iterator then -it models the following original iterator concepts depending on what -the Iterator argument models.

- ---- - - - - - - - - - - - - - - - - - - - -
If Iterator modelsthen transform_iterator models
Single Pass IteratorInput Iterator
Forward Traversal IteratorForward Iterator
Bidirectional Traversal IteratorBidirectional Iterator
Random Access Traversal IteratorRandom Access Iterator
-

If transform_iterator models Writable Lvalue Iterator then it is a -mutable iterator (as defined in the old iterator requirements).

-

transform_iterator<F1, X, R1, V1> is interoperable with -transform_iterator<F2, Y, R2, V2> if and only if X is -interoperable with Y.

-
-
-

transform_iterator operations

-

In addition to the operations required by the concepts modeled by -transform_iterator, transform_iterator provides the following -operations.

-

transform_iterator();

- --- - - - -
Returns:An instance of transform_iterator with m_f -and m_iterator default constructed.
-

transform_iterator(Iterator const& x, UnaryFunction f);

- --- - - - -
Returns:An instance of transform_iterator with m_f -initialized to f and m_iterator initialized to x.
-
-template<class F2, class I2, class R2, class V2>
-transform_iterator(
-      transform_iterator<F2, I2, R2, V2> const& t
-    , typename enable_if_convertible<I2, Iterator>::type* = 0      // exposition only
-    , typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition only
-);
-
- --- - - - - - -
Returns:An instance of transform_iterator with m_f -initialized to t.functor() and m_iterator initialized to -t.base().
Requires:OtherIterator is implicitly convertible to Iterator.
-

UnaryFunction functor() const;

- --- - - - -
Returns:m_f
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:m_f(*m_iterator)
-

transform_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

transform_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-
-
-
-

Filter iterator

- - - -

The filter iterator adaptor creates a view of an iterator range in -which some elements of the range are skipped. A predicate function -object controls which elements are skipped. When the predicate is -applied to an element, if it returns true then the element is -retained and if it returns false then the element is skipped -over. When skipping over elements, it is necessary for the filter -adaptor to know when to stop so as to avoid going past the end of the -underlying range. A filter iterator is therefore constructed with pair -of iterators indicating the range of elements in the unfiltered -sequence to be traversed.

-
-

Class template filter_iterator

- - - - -
-template <class Predicate, class Iterator>
-class filter_iterator
-{
- public:
-    typedef iterator_traits<Iterator>::value_type value_type;
-    typedef iterator_traits<Iterator>::reference reference;
-    typedef iterator_traits<Iterator>::pointer pointer;
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-    typedef /* see below */ iterator_category;
-
-    filter_iterator();
-    filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
-    filter_iterator(Iterator x, Iterator end = Iterator());
-    template<class OtherIterator>
-    filter_iterator(
-        filter_iterator<Predicate, OtherIterator> const& t
-        , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-        );
-    Predicate predicate() const;
-    Iterator end() const;
-    Iterator const& base() const;
-    reference operator*() const;
-    filter_iterator& operator++();
-private:
-    Predicate m_pred; // exposition only
-    Iterator m_iter;  // exposition only
-    Iterator m_end;   // exposition only
-};
-
-

If Iterator models Readable Lvalue Iterator and Bidirectional Traversal -Iterator then iterator_category is convertible to -std::bidirectional_iterator_tag. -Otherwise, if Iterator models Readable Lvalue Iterator and Forward Traversal -Iterator then iterator_category is convertible to -std::forward_iterator_tag. -Otherwise iterator_category is -convertible to std::input_iterator_tag.

-
-
-

filter_iterator requirements

-

The Iterator argument shall meet the requirements of Readable -Iterator and Single Pass Iterator or it shall meet the requirements of -Input Iterator.

-

The Predicate argument must be Assignable, Copy Constructible, and -the expression p(x) must be valid where p is an object of type -Predicate, x is an object of type -iterator_traits<Iterator>::value_type, and where the type of -p(x) must be convertible to bool.

-
-
-

filter_iterator models

-

The concepts that filter_iterator models are dependent on which -concepts the Iterator argument models, as specified in the -following tables.

- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Single Pass IteratorSingle Pass Iterator
Forward Traversal IteratorForward Traversal Iterator
Bidirectional Traversal IteratorBidirectional Traversal Iterator
- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable IteratorReadable Iterator
Writable IteratorWritable Iterator
Lvalue IteratorLvalue Iterator
- ---- - - - - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable Iterator, Single Pass IteratorInput Iterator
Readable Lvalue Iterator, Forward Traversal IteratorForward Iterator
Writable Lvalue Iterator, Forward Traversal IteratorMutable Forward Iterator
Writable Lvalue Iterator, Bidirectional IteratorMutable Bidirectional Iterator
-

filter_iterator<P1, X> is interoperable with filter_iterator<P2, Y> -if and only if X is interoperable with Y.

-
-
-

filter_iterator operations

-

In addition to those operations required by the concepts that -filter_iterator models, filter_iterator provides the following -operations.

-

filter_iterator();

- --- - - - - - -
Requires:Predicate and Iterator must be Default Constructible.
Effects:Constructs a filter_iterator whose``m_pred``, m_iter, and m_end -members are a default constructed.
-

filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());

- --- - - - -
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that f(*m_iter) == true -or else``m_iter == end``. The member m_pred is constructed from -f and m_end from end.
-

filter_iterator(Iterator x, Iterator end = Iterator());

- --- - - - - - -
Requires:Predicate must be Default Constructible and -Predicate is a class type (not a function pointer).
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that m_pred(*m_iter) == true -or else``m_iter == end``. The member m_pred is default constructed.
-
-template <class OtherIterator>
-filter_iterator(
-    filter_iterator<Predicate, OtherIterator> const& t
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-    );``
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs a filter iterator whose members are copied from t.
-

Predicate predicate() const;

- --- - - - -
Returns:m_pred
-

Iterator end() const;

- --- - - - -
Returns:m_end
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:*m_iter
-

filter_iterator& operator++();

- --- - - - - - -
Effects:Increments m_iter and then continues to -increment m_iter until either m_iter == m_end -or m_pred(*m_iter) == true.
Returns:*this
-
-
-
-

Counting iterator

- - - -

counting_iterator adapts an object by adding an operator* that -returns the current value of the object. All other iterator operations -are forwarded to the adapted object.

-
-

Class template counting_iterator

- - - -
-template <
-    class Incrementable
-  , class CategoryOrTraversal = use_default
-  , class Difference = use_default
->
-class counting_iterator
-{
-public:
-    typedef Incrementable value_type;
-    typedef const Incrementable& reference;
-    typedef const Incrementable* pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    counting_iterator();
-    counting_iterator(counting_iterator const& rhs);
-    explicit counting_iterator(Incrementable x);
-    Incrementable const& base() const;
-    reference operator*() const;
-    counting_iterator& operator++();
-    counting_iterator& operator--();
-private:
-    Incrementable m_inc; // exposition
-};
-
-

If the Difference argument is use_default then -difference_type is an unspecified signed integral -type. Otherwise difference_type is Difference.

-

iterator_category is determined according to the following -algorithm:

-
-if (CategoryOrTraversal is not use_default)
-    return CategoryOrTraversal
-else if (numeric_limits<Incrementable>::is_specialized)
-    return iterator-category(
-        random_access_traversal_tag, Incrementable, const Incrementable&)
-else
-    return iterator-category(
-         iterator_traversal<Incrementable>::type,
-         Incrementable, const Incrementable&)
-
-
-
[Note: implementers are encouraged to provide an implementation of
-
operator- and a difference_type that avoids overflows in -the cases where std::numeric_limits<Incrementable>::is_specialized -is true.]
-
-
-
-

counting_iterator requirements

-

The Incrementable argument shall be Copy Constructible and Assignable.

-

If iterator_category is convertible to forward_iterator_tag -or forward_traversal_tag, the following must be well-formed:

-
-Incrementable i, j;
-++i;         // pre-increment
-i == j;      // operator equal
-
-

If iterator_category is convertible to -bidirectional_iterator_tag or bidirectional_traversal_tag, -the following expression must also be well-formed:

-
---i
-
-

If iterator_category is convertible to -random_access_iterator_tag or random_access_traversal_tag, -the following must must also be valid:

-
-counting_iterator::difference_type n;
-i += n;
-n = i - j;
-i < j;
-
-
-
-

counting_iterator models

-

Specializations of counting_iterator model Readable Lvalue -Iterator. In addition, they model the concepts corresponding to the -iterator tags to which their iterator_category is convertible. -Also, if CategoryOrTraversal is not use_default then -counting_iterator models the concept corresponding to the iterator -tag CategoryOrTraversal. Otherwise, if -numeric_limits<Incrementable>::is_specialized, then -counting_iterator models Random Access Traversal Iterator. -Otherwise, counting_iterator models the same iterator traversal -concepts modeled by Incrementable.

-

counting_iterator<X,C1,D1> is interoperable with -counting_iterator<Y,C2,D2> if and only if X is -interoperable with Y.

-
-
-

counting_iterator operations

-

In addition to the operations required by the concepts modeled by -counting_iterator, counting_iterator provides the following -operations.

-

counting_iterator();

- --- - - - - - -
Requires:Incrementable is Default Constructible.
Effects:Default construct the member m_inc.
-

counting_iterator(counting_iterator const& rhs);

- --- - - - -
Effects:Construct member m_inc from rhs.m_inc.
-

explicit counting_iterator(Incrementable x);

- --- - - - -
Effects:Construct member m_inc from x.
-

reference operator*() const;

- --- - - - -
Returns:m_inc
-

counting_iterator& operator++();

- --- - - - - - -
Effects:++m_inc
Returns:*this
-

counting_iterator& operator--();

- --- - - - - - -
Effects:--m_inc
Returns:*this
-

Incrementable const& base() const;

- --- - - - -
Returns:m_inc
-
-
-
-

Function output iterator

- - - -

The function output iterator adaptor makes it easier to create custom -output iterators. The adaptor takes a unary function and creates a -model of Output Iterator. Each item assigned to the output iterator is -passed as an argument to the unary function. The motivation for this -iterator is that creating a conforming output iterator is non-trivial, -particularly because the proper implementation usually requires a -proxy object.

- -
-

Header

-
-#include <boost/function_output_iterator.hpp>
-
-
-template <class UnaryFunction>
-class function_output_iterator {
-public:
-  typedef std::output_iterator_tag iterator_category;
-  typedef void                     value_type;
-  typedef void                     difference_type;
-  typedef void                     pointer;
-  typedef void                     reference;
-
-  explicit function_output_iterator();
-
-  explicit function_output_iterator(const UnaryFunction& f);
-
-  /* see below */ operator*();
-  function_output_iterator& operator++();
-  function_output_iterator& operator++(int);
-private:
-  UnaryFunction m_f;     // exposition only
-};
-
-
-
-

function_output_iterator requirements

-

UnaryFunction must be Assignable and Copy Constructible.

-
-
-

function_output_iterator models

-

function_output_iterator is a model of the Writable and -Incrementable Iterator concepts.

-
-
-

function_output_iterator operations

-

explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());

- --- - - - -
Effects:Constructs an instance of function_output_iterator -with m_f constructed from f.
-

operator*();

- --- - - - -
Returns:An object r of unspecified type such that r = t -is equivalent to m_f(t) for all t.
-

function_output_iterator& operator++();

- --- - - - -
Returns:*this
-

function_output_iterator& operator++(int);

- --- - - - -
Returns:*this
- -
-
-
-
-
- - diff --git a/doc/facade-and-adaptor.pdf b/doc/facade-and-adaptor.pdf deleted file mode 100755 index a77daa4..0000000 Binary files a/doc/facade-and-adaptor.pdf and /dev/null differ diff --git a/doc/facade-and-adaptor.rst b/doc/facade-and-adaptor.rst deleted file mode 100644 index 1be63e8..0000000 --- a/doc/facade-and-adaptor.rst +++ /dev/null @@ -1,438 +0,0 @@ -.. 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) - -+++++++++++++++++++++++++++++ - Iterator Facade and Adaptor -+++++++++++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ - -:Number: This is a revised version of N1530_\ =03-0113, which was - accepted for Technical Report 1 by the C++ standard - committee's library working group. - -.. Version 1.9 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG. - -.. _n1530: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html - -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:abstract: We propose a set of class templates that help programmers - build standard-conforming iterators, both from scratch and - by adapting other iterators. - -.. contents:: Table of Contents - -============ - Motivation -============ - -Iterators play an important role in modern C++ programming. The -iterator is the central abstraction of the algorithms of the Standard -Library, allowing algorithms to be re-used in in a wide variety of -contexts. The C++ Standard Library contains a wide variety of useful -iterators. Every one of the standard containers comes with constant -and mutable iterators [#mutable]_, and also reverse versions of those -same iterators which traverse the container in the opposite direction. -The Standard also supplies ``istream_iterator`` and -``ostream_iterator`` for reading from and writing to streams, -``insert_iterator``, ``front_insert_iterator`` and -``back_insert_iterator`` for inserting elements into containers, and -``raw_storage_iterator`` for initializing raw memory [7]. - -Despite the many iterators supplied by the Standard Library, obvious -and useful iterators are missing, and creating new iterator types is -still a common task for C++ programmers. The literature documents -several of these, for example line_iterator [3] and Constant_iterator -[9]. The iterator abstraction is so powerful that we expect -programmers will always need to invent new iterator types. - -Although it is easy to create iterators that *almost* conform to the -standard, the iterator requirements contain subtleties which can make -creating an iterator which *actually* conforms quite difficult. -Further, the iterator interface is rich, containing many operators -that are technically redundant and tedious to implement. To automate -the repetitive work of constructing iterators, we propose -``iterator_facade``, an iterator base class template which provides -the rich interface of standard iterators and delegates its -implementation to member functions of the derived class. In addition -to reducing the amount of code necessary to create an iterator, the -``iterator_facade`` also provides compile-time error detection. -Iterator implementation mistakes that often go unnoticed are turned -into compile-time errors because the derived class implementation must -match the expectations of the ``iterator_facade``. - -A common pattern of iterator construction is the adaptation of one -iterator to form a new one. The functionality of an iterator is -composed of four orthogonal aspects: traversal, indirection, equality -comparison and distance measurement. Adapting an old iterator to -create a new one often saves work because one can reuse one aspect of -functionality while redefining the other. For example, the Standard -provides ``reverse_iterator``, which adapts any Bidirectional Iterator -by inverting its direction of traversal. As with plain iterators, -iterator adaptors defined outside the Standard have become commonplace -in the literature: - -* Checked iter[13] adds bounds-checking to an existing iterator. - -* The iterators of the View Template Library[14], which adapts - containers, are themselves adaptors over the underlying iterators. - -* Smart iterators [5] adapt an iterator's dereferencing behavior by - applying a function object to the object being referenced and - returning the result. - -* Custom iterators [4], in which a variety of adaptor types are enumerated. - -* Compound iterators [1], which access a slice out of a container of containers. - -* Several iterator adaptors from the MTL [12]. The MTL contains a - strided iterator, where each call to ``operator++()`` moves the - iterator ahead by some constant factor, and a scaled iterator, which - multiplies the dereferenced value by some constant. - -.. [#concept] We use the term concept to mean a set of requirements - that a type must satisfy to be used with a particular template - parameter. - -.. [#mutable] The term mutable iterator refers to iterators over objects that - can be changed by assigning to the dereferenced iterator, while - constant iterator refers to iterators over objects that cannot be - modified. - -To fulfill the need for constructing adaptors, we propose the -``iterator_adaptor`` class template. Instantiations of -``iterator_adaptor`` serve as a base classes for new iterators, -providing the default behavior of forwarding all operations to the -underlying iterator. The user can selectively replace these features -in the derived iterator class. This proposal also includes a number -of more specialized adaptors, such as the ``transform_iterator`` that -applies some user-specified function during the dereference of the -iterator. - -======================== - Impact on the Standard -======================== - -This proposal is purely an addition to the C++ standard library. -However, note that this proposal relies on the proposal for New -Iterator Concepts. - -======== - Design -======== - -Iterator Concepts -================= - -This proposal is formulated in terms of the new ``iterator concepts`` -as proposed in n1550_, since user-defined and especially adapted -iterators suffer from the well known categorization problems that are -inherent to the current iterator categories. - -.. _n1550: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html - -This proposal does not strictly depend on proposal n1550_, as there -is a direct mapping between new and old categories. This proposal -could be reformulated using this mapping if n1550_ was not accepted. - -Interoperability -================ - -The question of iterator interoperability is poorly addressed in the -current standard. There are currently two defect reports that are -concerned with interoperability issues. - -Issue 179_ concerns the fact that mutable container iterator types -are only required to be convertible to the corresponding constant -iterator types, but objects of these types are not required to -interoperate in comparison or subtraction expressions. This situation -is tedious in practice and out of line with the way built in types -work. This proposal implements the proposed resolution to issue -179_, as most standard library implementations do nowadays. In other -words, if an iterator type A has an implicit or user defined -conversion to an iterator type B, the iterator types are interoperable -and the usual set of operators are available. - -Issue 280_ concerns the current lack of interoperability between -reverse iterator types. The proposed new reverse_iterator template -fixes the issues raised in 280. It provides the desired -interoperability without introducing unwanted overloads. - -.. _179: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#179 -.. _280: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#280 - - -Iterator Facade -=============== - -.. include:: iterator_facade_body.rst - -Iterator Adaptor -================ - -.. include:: iterator_adaptor_body.rst - -Specialized Adaptors -==================== - -This proposal also contains several examples of specialized adaptors -which were easily implemented using ``iterator_adaptor``: - -* ``indirect_iterator``, which iterates over iterators, pointers, - or smart pointers and applies an extra level of dereferencing. - -* A new ``reverse_iterator``, which inverts the direction of a Base - iterator's motion, while allowing adapted constant and mutable - iterators to interact in the expected ways (unlike those in most - implementations of C++98). - -* ``transform_iterator``, which applies a user-defined function object - to the underlying values when dereferenced. - -* ``filter_iterator``, which provides a view of an iterator range in - which some elements of the underlying range are skipped. - -.. _counting: - -* ``counting_iterator``, which adapts any incrementable type - (e.g. integers, iterators) so that incrementing/decrementing the - adapted iterator and dereferencing it produces successive values of - the Base type. - -* ``function_output_iterator``, which makes it easier to create custom - output iterators. - -Based on examples in the Boost library, users have generated many new -adaptors, among them a permutation adaptor which applies some -permutation to a random access iterator, and a strided adaptor, which -adapts a random access iterator by multiplying its unit of motion by a -constant factor. In addition, the Boost Graph Library (BGL) uses -iterator adaptors to adapt other graph libraries, such as LEDA [10] -and Stanford GraphBase [8], to the BGL interface (which requires C++ -Standard compliant iterators). - -=============== - Proposed Text -=============== - - -Header ```` synopsis [lib.iterator.helper.synopsis] -======================================================================= - - -:: - - struct use_default; - - struct iterator_core_access { /* implementation detail */ }; - - template < - class Derived - , class Value - , class CategoryOrTraversal - , class Reference = Value& - , class Difference = ptrdiff_t - > - class iterator_facade; - - template < - class Derived - , class Base - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor; - - template < - class Iterator - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator; - - template - struct pointee; - - template - struct indirect_reference; - - template - class reverse_iterator; - - template < - class UnaryFunction - , class Iterator - , class Reference = use_default - , class Value = use_default - > - class transform_iterator; - - template - class filter_iterator; - - template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default - > - class counting_iterator; - - template - class function_output_iterator; - - - -Iterator facade [lib.iterator.facade] -===================================== - -.. include:: iterator_facade_abstract.rst - -Class template ``iterator_facade`` ----------------------------------- - -.. include:: iterator_facade_ref.rst - -Iterator adaptor [lib.iterator.adaptor] -======================================= - -.. include:: iterator_adaptor_abstract.rst - -Class template ``iterator_adaptor`` ------------------------------------ - -.. include:: iterator_adaptor_ref.rst - - -Specialized adaptors [lib.iterator.special.adaptors] -==================================================== - - -The ``enable_if_convertible::type`` expression used in -this section is for exposition purposes. The converting constructors -for specialized adaptors should be only be in an overload set provided -that an object of type ``X`` is implicitly convertible to an object of -type ``Y``. -The signatures involving ``enable_if_convertible`` should behave -*as-if* ``enable_if_convertible`` were defined to be:: - - template enable_if_convertible_impl - {}; - - template <> enable_if_convertible_impl - { struct type; }; - - template - struct enable_if_convertible - : enable_if_convertible_impl::value> - {}; - -If an expression other than the default argument is used to supply -the value of a function parameter whose type is written in terms -of ``enable_if_convertible``, the program is ill-formed, no -diagnostic required. - -[*Note:* The ``enable_if_convertible`` approach uses SFINAE to -take the constructor out of the overload set when the types are not -implicitly convertible. -] - - -Indirect iterator ------------------ - -.. include:: indirect_iterator_abstract.rst - -Class template ``pointee`` -.................................... - -.. include:: pointee_ref.rst - -Class template ``indirect_reference`` -..................................... - -.. include:: indirect_reference_ref.rst - -Class template ``indirect_iterator`` -.................................... - -.. include:: indirect_iterator_ref.rst - -Reverse iterator ----------------- - -.. include:: reverse_iterator_abstract.rst - -Class template ``reverse_iterator`` -................................... - -.. include:: reverse_iterator_ref.rst - - -Transform iterator ------------------- - -.. include:: transform_iterator_abstract.rst - -Class template ``transform_iterator`` -..................................... - -.. include:: transform_iterator_ref.rst - - -Filter iterator ---------------- - -.. include:: filter_iterator_abstract.rst - - -Class template ``filter_iterator`` -.................................. - -.. include:: filter_iterator_ref.rst - - -Counting iterator ------------------ - -.. include:: counting_iterator_abstract.rst - -Class template ``counting_iterator`` -.................................... - -.. include:: counting_iterator_ref.rst - - -Function output iterator ------------------------- - -.. include:: func_output_iter_abstract.rst - -Class template ``function_output_iterator`` -........................................... - -.. include:: func_output_iter_ref.rst - - - - -.. LocalWords: Abrahams Siek Witt istream ostream iter MTL strided interoperate - LocalWords: CRTP metafunctions inlining lvalue JGS incrementable BGL LEDA cv - LocalWords: GraphBase struct ptrdiff UnaryFunction const int typename bool pp - LocalWords: lhs rhs SFINAE markup iff tmp OtherDerived OtherIterator DWA foo - LocalWords: dereferenceable subobject AdaptableUnaryFunction impl pre ifdef'd - LocalWords: OtherIncrementable Coplien diff --git a/doc/facade_iterator_category.rst b/doc/facade_iterator_category.rst deleted file mode 100755 index 6b60d85..0000000 --- a/doc/facade_iterator_category.rst +++ /dev/null @@ -1,53 +0,0 @@ -.. |iterator-category| replace:: *iterator-category* -.. _iterator-category: - -.. parsed-literal:: - - *iterator-category*\ (C,R,V) := - if (C is convertible to std::input_iterator_tag - || C is convertible to std::output_iterator_tag - ) - return C - - else if (C is not convertible to incrementable_traversal_tag) - *the program is ill-formed* - - else return a type X satisfying the following two constraints: - - 1. X is convertible to X1, and not to any more-derived - type, where X1 is defined by: - - if (R is a reference type - && C is convertible to forward_traversal_tag) - { - if (C is convertible to random_access_traversal_tag) - X1 = random_access_iterator_tag - else if (C is convertible to bidirectional_traversal_tag) - X1 = bidirectional_iterator_tag - else - X1 = forward_iterator_tag - } - else - { - if (C is convertible to single_pass_traversal_tag - && R is convertible to V) - X1 = input_iterator_tag - else - X1 = C - } - - 2. |category-to-traversal|_\ (X) is convertible to the most - derived traversal tag type to which X is also - convertible, and not to any more-derived traversal tag - type. - -.. |category-to-traversal| replace:: *category-to-traversal* -.. _`category-to-traversal`: new-iter-concepts.html#category-to-traversal - -[Note: the intention is to allow ``iterator_category`` to be one of -the five original category tags when convertibility to one of the -traversal tags would add no information] - -.. Copyright David Abrahams 2004. Use, modification and distribution is -.. subject to 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) diff --git a/doc/filter_iterator.html b/doc/filter_iterator.html deleted file mode 100644 index 9b3eaa9..0000000 --- a/doc/filter_iterator.html +++ /dev/null @@ -1,689 +0,0 @@ - - - - - - -Filter Iterator - - - - - - - -
-

Filter Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract: - - -The filter iterator adaptor creates a view of an iterator range in -which some elements of the range are skipped. A predicate function -object controls which elements are skipped. When the predicate is -applied to an element, if it returns true then the element is -retained and if it returns false then the element is skipped -over. When skipping over elements, it is necessary for the filter -adaptor to know when to stop so as to avoid going past the end of the -underlying range. A filter iterator is therefore constructed with pair -of iterators indicating the range of elements in the unfiltered -sequence to be traversed.
- -
-

filter_iterator synopsis

- - - - -
-template <class Predicate, class Iterator>
-class filter_iterator
-{
- public:
-    typedef iterator_traits<Iterator>::value_type value_type;
-    typedef iterator_traits<Iterator>::reference reference;
-    typedef iterator_traits<Iterator>::pointer pointer;
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-    typedef /* see below */ iterator_category;
-
-    filter_iterator();
-    filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
-    filter_iterator(Iterator x, Iterator end = Iterator());
-    template<class OtherIterator>
-    filter_iterator(
-        filter_iterator<Predicate, OtherIterator> const& t
-        , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-        );
-    Predicate predicate() const;
-    Iterator end() const;
-    Iterator const& base() const;
-    reference operator*() const;
-    filter_iterator& operator++();
-private:
-    Predicate m_pred; // exposition only
-    Iterator m_iter;  // exposition only
-    Iterator m_end;   // exposition only
-};
-
-

If Iterator models Readable Lvalue Iterator and Bidirectional Traversal -Iterator then iterator_category is convertible to -std::bidirectional_iterator_tag. -Otherwise, if Iterator models Readable Lvalue Iterator and Forward Traversal -Iterator then iterator_category is convertible to -std::forward_iterator_tag. -Otherwise iterator_category is -convertible to std::input_iterator_tag.

-
-
-

filter_iterator requirements

-

The Iterator argument shall meet the requirements of Readable -Iterator and Single Pass Iterator or it shall meet the requirements of -Input Iterator.

-

The Predicate argument must be Assignable, Copy Constructible, and -the expression p(x) must be valid where p is an object of type -Predicate, x is an object of type -iterator_traits<Iterator>::value_type, and where the type of -p(x) must be convertible to bool.

-
-
-

filter_iterator models

-

The concepts that filter_iterator models are dependent on which -concepts the Iterator argument models, as specified in the -following tables.

- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Single Pass IteratorSingle Pass Iterator
Forward Traversal IteratorForward Traversal Iterator
Bidirectional Traversal IteratorBidirectional Traversal Iterator
- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable IteratorReadable Iterator
Writable IteratorWritable Iterator
Lvalue IteratorLvalue Iterator
- ---- - - - - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable Iterator, Single Pass IteratorInput Iterator
Readable Lvalue Iterator, Forward Traversal IteratorForward Iterator
Writable Lvalue Iterator, Forward Traversal IteratorMutable Forward Iterator
Writable Lvalue Iterator, Bidirectional IteratorMutable Bidirectional Iterator
-

filter_iterator<P1, X> is interoperable with filter_iterator<P2, Y> -if and only if X is interoperable with Y.

-
-
-

filter_iterator operations

-

In addition to those operations required by the concepts that -filter_iterator models, filter_iterator provides the following -operations.

-

filter_iterator();

- --- - - - - - -
Requires:Predicate and Iterator must be Default Constructible.
Effects:Constructs a filter_iterator whose``m_pred``, m_iter, and m_end -members are a default constructed.
-

filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());

- --- - - - -
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that f(*m_iter) == true -or else``m_iter == end``. The member m_pred is constructed from -f and m_end from end.
-

filter_iterator(Iterator x, Iterator end = Iterator());

- --- - - - - - -
Requires:Predicate must be Default Constructible and -Predicate is a class type (not a function pointer).
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that m_pred(*m_iter) == true -or else``m_iter == end``. The member m_pred is default constructed.
-
-template <class OtherIterator>
-filter_iterator(
-    filter_iterator<Predicate, OtherIterator> const& t
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-    );``
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs a filter iterator whose members are copied from t.
-

Predicate predicate() const;

- --- - - - -
Returns:m_pred
-

Iterator end() const;

- --- - - - -
Returns:m_end
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:*m_iter
-

filter_iterator& operator++();

- --- - - - - - -
Effects:Increments m_iter and then continues to -increment m_iter until either m_iter == m_end -or m_pred(*m_iter) == true.
Returns:*this
- - - -
-template <class Predicate, class Iterator>
-filter_iterator<Predicate,Iterator>
-make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
-
- --- - - - -
Returns:filter_iterator<Predicate,Iterator>(f, x, end)
-
-template <class Predicate, class Iterator>
-filter_iterator<Predicate,Iterator>
-make_filter_iterator(Iterator x, Iterator end = Iterator());
-
- --- - - - -
Returns:filter_iterator<Predicate,Iterator>(x, end)
- - - -
-
-

Example

-

This example uses filter_iterator and then -make_filter_iterator to output only the positive integers from an -array of integers. Then make_filter_iterator is is used to output -the integers greater than -2.

-
-struct is_positive_number {
-  bool operator()(int x) { return 0 < x; }
-};
-
-int main()
-{
-  int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 };
-  const int N = sizeof(numbers_)/sizeof(int);
-
-  typedef int* base_iterator;
-  base_iterator numbers(numbers_);
-
-  // Example using filter_iterator
-  typedef boost::filter_iterator<is_positive_number, base_iterator>
-    FilterIter;
-
-  is_positive_number predicate;
-  FilterIter filter_iter_first(predicate, numbers, numbers + N);
-  FilterIter filter_iter_last(predicate, numbers + N, numbers + N);
-
-  std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator<int>(std::cout, " "));
-  std::cout << std::endl;
-
-  // Example using make_filter_iterator()
-  std::copy(boost::make_filter_iterator<is_positive_number>(numbers, numbers + N),
-            boost::make_filter_iterator<is_positive_number>(numbers + N, numbers + N),
-            std::ostream_iterator<int>(std::cout, " "));
-  std::cout << std::endl;
-
-  // Another example using make_filter_iterator()
-  std::copy(
-      boost::make_filter_iterator(
-          std::bind2nd(std::greater<int>(), -2)
-        , numbers, numbers + N)
-
-    , boost::make_filter_iterator(
-          std::bind2nd(std::greater<int>(), -2)
-        , numbers + N, numbers + N)
-
-    , std::ostream_iterator<int>(std::cout, " ")
-  );
-
-  std::cout << std::endl;
-
-  return boost::exit_success;
-}
-
-

The output is:

-
-4 5 8
-4 5 8
-0 -1 4 5 8
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/filter_iterator.pdf b/doc/filter_iterator.pdf deleted file mode 100755 index 1d8a804..0000000 Binary files a/doc/filter_iterator.pdf and /dev/null differ diff --git a/doc/filter_iterator.rst b/doc/filter_iterator.rst deleted file mode 100644 index cfa8642..0000000 --- a/doc/filter_iterator.rst +++ /dev/null @@ -1,33 +0,0 @@ -.. 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) - -+++++++++++++++++ - Filter Iterator -+++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: filter_iterator_abstract.rst - -.. contents:: Table of Contents - -``filter_iterator`` synopsis -............................ - -.. include:: filter_iterator_ref.rst -.. include:: make_filter_iterator.rst - -.. include:: filter_iterator_eg.rst diff --git a/doc/filter_iterator_abstract.rst b/doc/filter_iterator_abstract.rst deleted file mode 100644 index 9524efa..0000000 --- a/doc/filter_iterator_abstract.rst +++ /dev/null @@ -1,15 +0,0 @@ -.. 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) - -The filter iterator adaptor creates a view of an iterator range in -which some elements of the range are skipped. A predicate function -object controls which elements are skipped. When the predicate is -applied to an element, if it returns ``true`` then the element is -retained and if it returns ``false`` then the element is skipped -over. When skipping over elements, it is necessary for the filter -adaptor to know when to stop so as to avoid going past the end of the -underlying range. A filter iterator is therefore constructed with pair -of iterators indicating the range of elements in the unfiltered -sequence to be traversed. - diff --git a/doc/filter_iterator_eg.rst b/doc/filter_iterator_eg.rst deleted file mode 100644 index dc2770e..0000000 --- a/doc/filter_iterator_eg.rst +++ /dev/null @@ -1,72 +0,0 @@ -.. 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) - -Example -....... - -This example uses ``filter_iterator`` and then -``make_filter_iterator`` to output only the positive integers from an -array of integers. Then ``make_filter_iterator`` is is used to output -the integers greater than ``-2``. - -:: - - struct is_positive_number { - bool operator()(int x) { return 0 < x; } - }; - - int main() - { - int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 }; - const int N = sizeof(numbers_)/sizeof(int); - - typedef int* base_iterator; - base_iterator numbers(numbers_); - - // Example using filter_iterator - typedef boost::filter_iterator - FilterIter; - - is_positive_number predicate; - FilterIter filter_iter_first(predicate, numbers, numbers + N); - FilterIter filter_iter_last(predicate, numbers + N, numbers + N); - - std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example using make_filter_iterator() - std::copy(boost::make_filter_iterator(numbers, numbers + N), - boost::make_filter_iterator(numbers + N, numbers + N), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Another example using make_filter_iterator() - std::copy( - boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers, numbers + N) - - , boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers + N, numbers + N) - - , std::ostream_iterator(std::cout, " ") - ); - - std::cout << std::endl; - - return boost::exit_success; - } - - -The output is:: - - 4 5 8 - 4 5 8 - 0 -1 4 5 8 - - -The source code for this example can be found `here`__. - -__ ../example/filter_iterator_example.cpp diff --git a/doc/filter_iterator_ref.rst b/doc/filter_iterator_ref.rst deleted file mode 100644 index 1759788..0000000 --- a/doc/filter_iterator_ref.rst +++ /dev/null @@ -1,177 +0,0 @@ -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt -.. 2004. Use, modification and distribution is subject to 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) - -:: - - template - class filter_iterator - { - public: - typedef iterator_traits::value_type value_type; - typedef iterator_traits::reference reference; - typedef iterator_traits::pointer pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - filter_iterator(); - filter_iterator(Predicate f, Iterator x, Iterator end = Iterator()); - filter_iterator(Iterator x, Iterator end = Iterator()); - template - filter_iterator( - filter_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition - ); - Predicate predicate() const; - Iterator end() const; - Iterator const& base() const; - reference operator*() const; - filter_iterator& operator++(); - private: - Predicate m_pred; // exposition only - Iterator m_iter; // exposition only - Iterator m_end; // exposition only - }; - - -If ``Iterator`` models Readable Lvalue Iterator and Bidirectional Traversal -Iterator then ``iterator_category`` is convertible to -``std::bidirectional_iterator_tag``. -Otherwise, if ``Iterator`` models Readable Lvalue Iterator and Forward Traversal -Iterator then ``iterator_category`` is convertible to -``std::forward_iterator_tag``. -Otherwise ``iterator_category`` is -convertible to ``std::input_iterator_tag``. - - -``filter_iterator`` requirements -................................ - -The ``Iterator`` argument shall meet the requirements of Readable -Iterator and Single Pass Iterator or it shall meet the requirements of -Input Iterator. - -The ``Predicate`` argument must be Assignable, Copy Constructible, and -the expression ``p(x)`` must be valid where ``p`` is an object of type -``Predicate``, ``x`` is an object of type -``iterator_traits::value_type``, and where the type of -``p(x)`` must be convertible to ``bool``. - - -``filter_iterator`` models -.......................... - -The concepts that ``filter_iterator`` models are dependent on which -concepts the ``Iterator`` argument models, as specified in the -following tables. - -+---------------------------------+------------------------------------------+ -|If ``Iterator`` models |then ``filter_iterator`` models | -+=================================+==========================================+ -|Single Pass Iterator |Single Pass Iterator | -+---------------------------------+------------------------------------------+ -|Forward Traversal Iterator |Forward Traversal Iterator | -+---------------------------------+------------------------------------------+ -|Bidirectional Traversal Iterator |Bidirectional Traversal Iterator | -+---------------------------------+------------------------------------------+ - -+--------------------------------+----------------------------------------------+ -| If ``Iterator`` models | then ``filter_iterator`` models | -+================================+==============================================+ -| Readable Iterator | Readable Iterator | -+--------------------------------+----------------------------------------------+ -| Writable Iterator | Writable Iterator | -+--------------------------------+----------------------------------------------+ -| Lvalue Iterator | Lvalue Iterator | -+--------------------------------+----------------------------------------------+ - -+-------------------------------------------------------+---------------------------------+ -|If ``Iterator`` models | then ``filter_iterator`` models | -+=======================================================+=================================+ -|Readable Iterator, Single Pass Iterator | Input Iterator | -+-------------------------------------------------------+---------------------------------+ -|Readable Lvalue Iterator, Forward Traversal Iterator | Forward Iterator | -+-------------------------------------------------------+---------------------------------+ -|Writable Lvalue Iterator, Forward Traversal Iterator | Mutable Forward Iterator | -+-------------------------------------------------------+---------------------------------+ -|Writable Lvalue Iterator, Bidirectional Iterator | Mutable Bidirectional Iterator | -+-------------------------------------------------------+---------------------------------+ - - -``filter_iterator`` is interoperable with ``filter_iterator`` -if and only if ``X`` is interoperable with ``Y``. - - -``filter_iterator`` operations -.............................. - -In addition to those operations required by the concepts that -``filter_iterator`` models, ``filter_iterator`` provides the following -operations. - - -``filter_iterator();`` - -:Requires: ``Predicate`` and ``Iterator`` must be Default Constructible. -:Effects: Constructs a ``filter_iterator`` whose``m_pred``, ``m_iter``, and ``m_end`` - members are a default constructed. - - -``filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());`` - -:Effects: Constructs a ``filter_iterator`` where ``m_iter`` is either - the first position in the range ``[x,end)`` such that ``f(*m_iter) == true`` - or else``m_iter == end``. The member ``m_pred`` is constructed from - ``f`` and ``m_end`` from ``end``. - - - -``filter_iterator(Iterator x, Iterator end = Iterator());`` - -:Requires: ``Predicate`` must be Default Constructible and - ``Predicate`` is a class type (not a function pointer). -:Effects: Constructs a ``filter_iterator`` where ``m_iter`` is either - the first position in the range ``[x,end)`` such that ``m_pred(*m_iter) == true`` - or else``m_iter == end``. The member ``m_pred`` is default constructed. - - -:: - - template - filter_iterator( - filter_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition - );`` - -:Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. -:Effects: Constructs a filter iterator whose members are copied from ``t``. - - -``Predicate predicate() const;`` - -:Returns: ``m_pred`` - - -``Iterator end() const;`` - -:Returns: ``m_end`` - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - - -``reference operator*() const;`` - -:Returns: ``*m_iter`` - - -``filter_iterator& operator++();`` - -:Effects: Increments ``m_iter`` and then continues to - increment ``m_iter`` until either ``m_iter == m_end`` - or ``m_pred(*m_iter) == true``. -:Returns: ``*this`` diff --git a/doc/func_output_iter_abstract.rst b/doc/func_output_iter_abstract.rst deleted file mode 100644 index d4a700f..0000000 --- a/doc/func_output_iter_abstract.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. 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) - -The function output iterator adaptor makes it easier to create custom -output iterators. The adaptor takes a unary function and creates a -model of Output Iterator. Each item assigned to the output iterator is -passed as an argument to the unary function. The motivation for this -iterator is that creating a conforming output iterator is non-trivial, -particularly because the proper implementation usually requires a -proxy object. - diff --git a/doc/func_output_iter_ref.rst b/doc/func_output_iter_ref.rst deleted file mode 100644 index e00eab7..0000000 --- a/doc/func_output_iter_ref.rst +++ /dev/null @@ -1,73 +0,0 @@ -.. 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) - -Header -...... - -:: - - #include - -:: - - template - class function_output_iterator { - public: - typedef std::output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - - explicit function_output_iterator(); - - explicit function_output_iterator(const UnaryFunction& f); - - /* see below */ operator*(); - function_output_iterator& operator++(); - function_output_iterator& operator++(int); - private: - UnaryFunction m_f; // exposition only - }; - - - -``function_output_iterator`` requirements -......................................... - -``UnaryFunction`` must be Assignable and Copy Constructible. - - - -``function_output_iterator`` models -................................... - -``function_output_iterator`` is a model of the Writable and -Incrementable Iterator concepts. - - - -``function_output_iterator`` operations -....................................... - -``explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());`` - -:Effects: Constructs an instance of ``function_output_iterator`` - with ``m_f`` constructed from ``f``. - - -``operator*();`` - -:Returns: An object ``r`` of unspecified type such that ``r = t`` - is equivalent to ``m_f(t)`` for all ``t``. - - -``function_output_iterator& operator++();`` - -:Returns: ``*this`` - - -``function_output_iterator& operator++(int);`` - -:Returns: ``*this`` diff --git a/doc/function_output_iterator.html b/doc/function_output_iterator.html deleted file mode 100644 index bea15ba..0000000 --- a/doc/function_output_iterator.html +++ /dev/null @@ -1,467 +0,0 @@ - - - - - - -Function Output Iterator - - - - - - - -
-

Function Output Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract: - - -The function output iterator adaptor makes it easier to create custom -output iterators. The adaptor takes a unary function and creates a -model of Output Iterator. Each item assigned to the output iterator is -passed as an argument to the unary function. The motivation for this -iterator is that creating a conforming output iterator is non-trivial, -particularly because the proper implementation usually requires a -proxy object.
- - - - -
-

Header

-
-#include <boost/function_output_iterator.hpp>
-
-
-template <class UnaryFunction>
-class function_output_iterator {
-public:
-  typedef std::output_iterator_tag iterator_category;
-  typedef void                     value_type;
-  typedef void                     difference_type;
-  typedef void                     pointer;
-  typedef void                     reference;
-
-  explicit function_output_iterator();
-
-  explicit function_output_iterator(const UnaryFunction& f);
-
-  /* see below */ operator*();
-  function_output_iterator& operator++();
-  function_output_iterator& operator++(int);
-private:
-  UnaryFunction m_f;     // exposition only
-};
-
-
-
-

function_output_iterator requirements

-

UnaryFunction must be Assignable and Copy Constructible.

-
-
-

function_output_iterator models

-

function_output_iterator is a model of the Writable and -Incrementable Iterator concepts.

-
-
-

function_output_iterator operations

-

explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());

- --- - - - -
Effects:Constructs an instance of function_output_iterator -with m_f constructed from f.
-

operator*();

- --- - - - -
Returns:An object r of unspecified type such that r = t -is equivalent to m_f(t) for all t.
-

function_output_iterator& operator++();

- --- - - - -
Returns:*this
-

function_output_iterator& operator++(int);

- --- - - - -
Returns:*this
- - - -
-
-

Example

-
-struct string_appender
-{
-    string_appender(std::string& s)
-        : m_str(&s)
-    {}
-
-    void operator()(const std::string& x) const
-    {
-        *m_str += x;
-    }
-
-    std::string* m_str;
-};
-
-int main(int, char*[])
-{
-  std::vector<std::string> x;
-  x.push_back("hello");
-  x.push_back(" ");
-  x.push_back("world");
-  x.push_back("!");
-
-  std::string s = "";
-  std::copy(x.begin(), x.end(),
-            boost::make_function_output_iterator(string_appender(s)));
-
-  std::cout << s << std::endl;
-
-  return 0;
-}
-
-
-
- - diff --git a/doc/function_output_iterator.pdf b/doc/function_output_iterator.pdf deleted file mode 100755 index cef2274..0000000 Binary files a/doc/function_output_iterator.pdf and /dev/null differ diff --git a/doc/function_output_iterator.rst b/doc/function_output_iterator.rst deleted file mode 100644 index 8018af5..0000000 --- a/doc/function_output_iterator.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. 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) - -++++++++++++++++++++++++++ - Function Output Iterator -++++++++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: func_output_iter_abstract.rst - -.. contents:: Table of Contents - -.. include:: func_output_iter_ref.rst -.. include:: function_output_iterator_eg.rst \ No newline at end of file diff --git a/doc/function_output_iterator_eg.rst b/doc/function_output_iterator_eg.rst deleted file mode 100644 index ab09f2d..0000000 --- a/doc/function_output_iterator_eg.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. 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) - -Example -....... - -:: - - struct string_appender - { - string_appender(std::string& s) - : m_str(&s) - {} - - void operator()(const std::string& x) const - { - *m_str += x; - } - - std::string* m_str; - }; - - int main(int, char*[]) - { - std::vector x; - x.push_back("hello"); - x.push_back(" "); - x.push_back("world"); - x.push_back("!"); - - std::string s = ""; - std::copy(x.begin(), x.end(), - boost::make_function_output_iterator(string_appender(s))); - - std::cout << s << std::endl; - - return 0; - } diff --git a/doc/generate.py b/doc/generate.py deleted file mode 100644 index f5d0de8..0000000 --- a/doc/generate.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/python -# Copyright David Abrahams 2004. Use, modification and distribution is -# subject to 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) - -# -# Generate html, TeX, and PDF versions of all the source files -# -import os -import sys - -from syscmd import syscmd -from sources import sources - -if 0: - for s in sources: - syscmd('boosthtml %s' % s) -else: - extensions = ('html', 'pdf') - - if len(sys.argv) > 1: - extensions = sys.argv[1:] - - all = [ '%s.%s' % (os.path.splitext(s)[0],ext) - for ext in extensions - for s in sources - ] - - print 'make %s' % ' '.join(all) - syscmd('make %s' % ' '.join(all)) - - diff --git a/doc/index.html b/doc/index.html deleted file mode 100755 index eef53b1..0000000 --- a/doc/index.html +++ /dev/null @@ -1,521 +0,0 @@ - - - - - - -The Boost.Iterator Library Boost - - - - - - diff --git a/doc/index.rst b/doc/index.rst deleted file mode 100755 index 32db09a..0000000 --- a/doc/index.rst +++ /dev/null @@ -1,323 +0,0 @@ -.. 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) - -+++++++++++++++++++++++++++++++++++++++++++++++++ - The Boost.Iterator Library |(logo)|__ -+++++++++++++++++++++++++++++++++++++++++++++++++ - -.. |(logo)| image:: ../../../boost.png - :alt: Boost - -__ ../../../index.htm - - -------------------------------------- - - -:Authors: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organizations: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ - -:copyright: Copyright David Abrahams, Jeremy Siek, Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:Abstract: The Boost Iterator Library contains two parts. The first - is a system of concepts_ which extend the C++ standard - iterator requirements. The second is a framework of - components for building iterators based on these - extended concepts and includes several useful iterator - adaptors. The extended iterator concepts have been - carefully designed so that old-style iterators - can fit in the new concepts and so that new-style - iterators will be compatible with old-style algorithms, - though algorithms may need to be updated if they want to - take full advantage of the new-style iterator - capabilities. Several components of this library have - been accepted into the C++ standard technical report. - The components of the Boost Iterator Library replace the - older Boost Iterator Adaptor Library. - -.. _concepts: ../../../more/generic_programming.html#concept - -.. contents:: **Table of Contents** - - -------------------------------------- - - -===================== - New-Style Iterators -===================== - -The iterator categories defined in C++98 are extremely limiting -because they bind together two orthogonal concepts: traversal and -element access. For example, because a random access iterator is -required to return a reference (and not a proxy) when dereferenced, -it is impossible to capture the capabilities of -``vector::iterator`` using the C++98 categories. This is the -infamous "``vector`` is not a container, and its iterators -aren't random access iterators", debacle about which Herb Sutter -wrote two papers for the standards comittee (n1185_ and n1211_), -and a `Guru of the Week`__. New-style iterators go well beyond -patching up ``vector``, though: there are lots of other -iterators already in use which can't be adequately represented by -the existing concepts. For details about the new iterator -concepts, see our - -.. _n1185: http://www.gotw.ca/publications/N1185.pdf -.. _n1211: http://www.gotw.ca/publications/N1211.pdf -__ http://www.gotw.ca/gotw/050.htm - - - `Standard Proposal For New-Style Iterators`__ (PDF__) - -__ new-iter-concepts.html -__ new-iter-concepts.pdf - -============================= - Iterator Facade and Adaptor -============================= - -Writing standard-conforming iterators is tricky, but the need comes -up often. In order to ease the implementation of new iterators, -the Boost.Iterator library provides the |facade| class template, -which implements many useful defaults and compile-time checks -designed to help the iterator author ensure that his iterator is -correct. - -It is also common to define a new iterator that is similar to some -underlying iterator or iterator-like type, but that modifies some -aspect of the underlying type's behavior. For that purpose, the -library supplies the |adaptor| class template, which is specially -designed to take advantage of as much of the underlying type's -behavior as possible. - -The documentation for these two classes can be found at the following -web pages: - -* |facade|_ (PDF__) - -* |adaptor|_ (PDF__) - - -.. |facade| replace:: ``iterator_facade`` -.. _facade: iterator_facade.html -__ iterator_facade.pdf - -.. |adaptor| replace:: ``iterator_adaptor`` -.. _adaptor: iterator_adaptor.html -__ iterator_adaptor.pdf - -Both |facade| and |adaptor| as well as many of the `specialized -adaptors`_ mentioned below have been proposed for standardization, -and accepted into the first C++ technical report; see our - - `Standard Proposal For Iterator Facade and Adaptor`__ (PDF__) - -for more details. - -__ facade-and-adaptor.html -__ facade-and-adaptor.pdf - -====================== - Specialized Adaptors -====================== - -The iterator library supplies a useful suite of standard-conforming -iterator templates based on the Boost `iterator facade and adaptor`_. - -* |counting|_ (PDF__): an iterator over a sequence of consecutive values. - Implements a "lazy sequence" - -* |filter|_ (PDF__): an iterator over the subset of elements of some - sequence which satisfy a given predicate - -* |function|_ (PDF__): an output iterator wrapping a unary function - object; each time an element is written into the dereferenced - iterator, it is passed as a parameter to the function object. - -* |indirect|_ (PDF__): an iterator over the objects *pointed-to* by the - elements of some sequence. - -* |permutation|_ (PDF__): an iterator over the elements of some random-access - sequence, rearranged according to some sequence of integer indices. - -* |reverse|_ (PDF__): an iterator which traverses the elements of some - bidirectional sequence in reverse. Corrects many of the - shortcomings of C++98's ``std::reverse_iterator``. - -* |shared|_: an iterator over elements of a container whose - lifetime is maintained by a |shared_ptr|_ stored in the iterator. - -* |transform|_ (PDF__): an iterator over elements which are the result of - applying some functional transformation to the elements of an - underlying sequence. This component also replaces the old - ``projection_iterator_adaptor``. - -* |zip|_ (PDF__): an iterator over tuples of the elements at corresponding - positions of heterogeneous underlying iterators. - -.. |counting| replace:: ``counting_iterator`` -.. _counting: counting_iterator.html -__ counting_iterator.pdf - -.. |filter| replace:: ``filter_iterator`` -.. _filter: filter_iterator.html -__ filter_iterator.pdf - -.. |function| replace:: ``function_output_iterator`` -.. _function: function_output_iterator.html -__ function_output_iterator.pdf - -.. |indirect| replace:: ``indirect_iterator`` -.. _indirect: indirect_iterator.html -__ indirect_iterator.pdf - -.. |permutation| replace:: ``permutation_iterator`` -.. _permutation: permutation_iterator.html -__ permutation_iterator.pdf - -.. |reverse| replace:: ``reverse_iterator`` -.. _reverse: reverse_iterator.html -__ reverse_iterator.pdf - -.. |shared| replace:: ``shared_container_iterator`` -.. _shared: ../../utility/shared_container_iterator.html - -.. |transform| replace:: ``transform_iterator`` -.. _transform: transform_iterator.html -__ transform_iterator.pdf - -.. |zip| replace:: ``zip_iterator`` -.. _zip: zip_iterator.html -__ zip_iterator.pdf - -.. |shared_ptr| replace:: ``shared_ptr`` -.. _shared_ptr: ../../smart_ptr/shared_ptr.htm - -==================== - Iterator Utilities -==================== - -Traits ------- - -* |pointee|_ (PDF__): Provides the capability to deduce the referent types - of pointers, smart pointers and iterators in generic code. Used - in |indirect|. - -* |iterator_traits|_ (PDF__): Provides MPL_\ -compatible metafunctions which - retrieve an iterator's traits. Also corrects for the deficiencies - of broken implementations of ``std::iterator_traits``. - -.. * |interoperable|_ (PDF__): Provides an MPL_\ -compatible metafunction for - testing iterator interoperability - -.. |pointee| replace:: ``pointee.hpp`` -.. _pointee: pointee.html -__ pointee.pdf - -.. |iterator_traits| replace:: ``iterator_traits.hpp`` -.. _iterator_traits: iterator_traits.html -__ iterator_traits.pdf - -.. |interoperable| replace:: ``interoperable.hpp`` -.. _interoperable: interoperable.html -.. comment! __ interoperable.pdf - -.. _MPL: ../../mpl/doc/index.html - -Testing and Concept Checking ----------------------------- - -* |iterator_concepts|_ (PDF__): Concept checking classes for the new iterator concepts. - -* |iterator_archetypes|_ (PDF__): Concept archetype classes for the new iterators concepts. - -.. |iterator_concepts| replace:: ``iterator_concepts.hpp`` -.. _iterator_concepts: iterator_concepts.html -__ iterator_concepts.pdf - -.. |iterator_archetypes| replace:: ``iterator_archetypes.hpp`` -.. _iterator_archetypes: iterator_archetypes.html -__ iterator_archetypes.pdf - -======================================================= - Upgrading from the old Boost Iterator Adaptor Library -======================================================= - -.. _Upgrading: - -If you have been using the old Boost Iterator Adaptor library to -implement iterators, you probably wrote a ``Policies`` class which -captures the core operations of your iterator. In the new library -design, you'll move those same core operations into the body of the -iterator class itself. If you were writing a family of iterators, -you probably wrote a `type generator`_ to build the -``iterator_adaptor`` specialization you needed; in the new library -design you don't need a type generator (though may want to keep it -around as a compatibility aid for older code) because, due to the -use of the Curiously Recurring Template Pattern (CRTP) [Cop95]_, -you can now define the iterator class yourself and acquire -functionality through inheritance from ``iterator_facade`` or -``iterator_adaptor``. As a result, you also get much finer control -over how your iterator works: you can add additional constructors, -or even override the iterator functionality provided by the -library. - -.. _`type generator`: ../../../more/generic_programming.html#type_generator - -If you're looking for the old ``projection_iterator`` component, -its functionality has been merged into ``transform_iterator``: as -long as the function object's ``result_type`` (or the ``Reference`` -template argument, if explicitly specified) is a true reference -type, ``transform_iterator`` will behave like -``projection_iterator`` used to. - -========= - History -========= - -In 2000 Dave Abrahams was writing an iterator for a container of -pointers, which would access the pointed-to elements when -dereferenced. Naturally, being a library writer, he decided to -generalize the idea and the Boost Iterator Adaptor library was born. -Dave was inspired by some writings of Andrei Alexandrescu and chose a -policy based design (though he probably didn't capture Andrei's idea -very well - there was only one policy class for all the iterator's -orthogonal properties). Soon Jeremy Siek realized he would need the -library and they worked together to produce a "Boostified" version, -which was reviewed and accepted into the library. They wrote a paper -and made several important revisions of the code. - -Eventually, several shortcomings of the older library began to make -the need for a rewrite apparent. Dave and Jeremy started working -at the Santa Cruz C++ committee meeting in 2002, and had quickly -generated a working prototype. At the urging of Mat Marcus, they -decided to use the GenVoca/CRTP pattern approach, and moved the -policies into the iterator class itself. Thomas Witt expressed -interest and became the voice of strict compile-time checking for -the project, adding uses of the SFINAE technique to eliminate false -converting constructors and operators from the overload set. He -also recognized the need for a separate ``iterator_facade``, and -factored it out of ``iterator_adaptor``. Finally, after a -near-complete rewrite of the prototype, they came up with the -library you see today. - -.. [Cop95] [Coplien, 1995] Coplien, J., Curiously Recurring Template - Patterns, C++ Report, February 1995, pp. 24-27. - -.. - LocalWords: Abrahams Siek Witt const bool Sutter's WG int UL LI href Lvalue - LocalWords: ReadableIterator WritableIterator SwappableIterator cv pre iter - LocalWords: ConstantLvalueIterator MutableLvalueIterator CopyConstructible TR - LocalWords: ForwardTraversalIterator BidirectionalTraversalIterator lvalue - LocalWords: RandomAccessTraversalIterator dereferenceable Incrementable tmp - LocalWords: incrementable xxx min prev inplace png oldeqnew AccessTag struct - LocalWords: TraversalTag typename lvalues DWA Hmm JGS diff --git a/doc/indirect_iterator.html b/doc/indirect_iterator.html deleted file mode 100644 index 11ea71f..0000000 --- a/doc/indirect_iterator.html +++ /dev/null @@ -1,621 +0,0 @@ - - - - - - -Indirect Iterator - - - - - - - -
-

Indirect Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract: - - -indirect_iterator adapts an iterator by applying an -extra dereference inside of operator*(). For example, this -iterator adaptor makes it possible to view a container of pointers -(e.g. list<foo*>) as if it were a container of the pointed-to type -(e.g. list<foo>). indirect_iterator depends on two -auxiliary traits, pointee and indirect_reference, to -provide support for underlying iterators whose value_type is -not an iterator.
- -
-

indirect_iterator synopsis

- - - -
-template <
-    class Iterator
-  , class Value = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference = use_default
-  , class Difference = use_default
->
-class indirect_iterator
-{
- public:
-    typedef /* see below */ value_type;
-    typedef /* see below */ reference;
-    typedef /* see below */ pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    indirect_iterator();
-    indirect_iterator(Iterator x);
-
-    template <
-        class Iterator2, class Value2, class Category2
-      , class Reference2, class Difference2
-    >
-    indirect_iterator(
-        indirect_iterator<
-             Iterator2, Value2, Category2, Reference2, Difference2
-        > const& y
-      , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-    );
-
-    Iterator const& base() const;
-    reference operator*() const;
-    indirect_iterator& operator++();
-    indirect_iterator& operator--();
-private:
-   Iterator m_iterator; // exposition
-};
-
-

The member types of indirect_iterator are defined according to -the following pseudo-code, where V is -iterator_traits<Iterator>::value_type

-
-if (Value is use_default) then
-    typedef remove_const<pointee<V>::type>::type value_type;
-else
-    typedef remove_const<Value>::type value_type;
-
-if (Reference is use_default) then
-    if (Value is use_default) then
-        typedef indirect_reference<V>::type reference;
-    else
-        typedef Value& reference;
-else
-    typedef Reference reference;
-
-if (Value is use_default) then
-    typedef pointee<V>::type* pointer;
-else
-    typedef Value* pointer;
-
-if (Difference is use_default)
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-else
-    typedef Difference difference_type;
-
-if (CategoryOrTraversal is use_default)
-    typedef iterator-category (
-        iterator_traversal<Iterator>::type,``reference``,``value_type``
-    ) iterator_category;
-else
-    typedef iterator-category (
-        CategoryOrTraversal,``reference``,``value_type``
-    ) iterator_category;
-
-
-
-

indirect_iterator requirements

-

The expression *v, where v is an object of -iterator_traits<Iterator>::value_type, shall be valid -expression and convertible to reference. Iterator shall -model the traversal concept indicated by iterator_category. -Value, Reference, and Difference shall be chosen so -that value_type, reference, and difference_type meet -the requirements indicated by iterator_category.

-

[Note: there are further requirements on the -iterator_traits<Iterator>::value_type if the Value -parameter is not use_default, as implied by the algorithm for -deducing the default for the value_type member.]

-
-
-

indirect_iterator models

-

In addition to the concepts indicated by iterator_category -and by iterator_traversal<indirect_iterator>::type, a -specialization of indirect_iterator models the following -concepts, Where v is an object of -iterator_traits<Iterator>::value_type:

-
-
    -
  • Readable Iterator if reference(*v) is convertible to -value_type.
  • -
  • Writable Iterator if reference(*v) = t is a valid -expression (where t is an object of type -indirect_iterator::value_type)
  • -
  • Lvalue Iterator if reference is a reference type.
  • -
-
-

indirect_iterator<X,V1,C1,R1,D1> is interoperable with -indirect_iterator<Y,V2,C2,R2,D2> if and only if X is -interoperable with Y.

-
-
-

indirect_iterator operations

-

In addition to the operations required by the concepts described -above, specializations of indirect_iterator provide the -following operations.

-

indirect_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of indirect_iterator with -a default-constructed m_iterator.
-

indirect_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of indirect_iterator with -m_iterator copy constructed from x.
-
-template <
-    class Iterator2, class Value2, unsigned Access, class Traversal
-  , class Reference2, class Difference2
->
-indirect_iterator(
-    indirect_iterator<
-         Iterator2, Value2, Access, Traversal, Reference2, Difference2
-    > const& y
-  , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:Iterator2 is implicitly convertible to Iterator.
Effects:Constructs an instance of indirect_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:**m_iterator
-

indirect_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

indirect_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
- - - -
-
-

Example

-

This example prints an array of characters, using -indirect_iterator to access the array of characters through an -array of pointers. Next indirect_iterator is used with the -transform algorithm to copy the characters (incremented by one) to -another array. A constant indirect iterator is used for the source and -a mutable indirect iterator is used for the destination. The last part -of the example prints the original array of characters, but this time -using the make_indirect_iterator helper function.

-
-char characters[] = "abcdefg";
-const int N = sizeof(characters)/sizeof(char) - 1; // -1 since characters has a null char
-char* pointers_to_chars[N];                        // at the end.
-for (int i = 0; i < N; ++i)
-  pointers_to_chars[i] = &characters[i];
-
-// Example of using indirect_iterator
-
-boost::indirect_iterator<char**, char>
-  indirect_first(pointers_to_chars), indirect_last(pointers_to_chars + N);
-
-std::copy(indirect_first, indirect_last, std::ostream_iterator<char>(std::cout, ","));
-std::cout << std::endl;
-
-
-// Example of making mutable and constant indirect iterators
-
-char mutable_characters[N];
-char* pointers_to_mutable_chars[N];
-for (int j = 0; j < N; ++j)
-  pointers_to_mutable_chars[j] = &mutable_characters[j];
-
-boost::indirect_iterator<char* const*> mutable_indirect_first(pointers_to_mutable_chars),
-  mutable_indirect_last(pointers_to_mutable_chars + N);
-boost::indirect_iterator<char* const*, char const> const_indirect_first(pointers_to_chars),
-  const_indirect_last(pointers_to_chars + N);
-
-std::transform(const_indirect_first, const_indirect_last,
-               mutable_indirect_first, std::bind1st(std::plus<char>(), 1));
-
-std::copy(mutable_indirect_first, mutable_indirect_last,
-          std::ostream_iterator<char>(std::cout, ","));
-std::cout << std::endl;
-
-
-// Example of using make_indirect_iterator()
-
-std::copy(boost::make_indirect_iterator(pointers_to_chars),
-          boost::make_indirect_iterator(pointers_to_chars + N),
-          std::ostream_iterator<char>(std::cout, ","));
-std::cout << std::endl;
-
-

The output is:

-
-a,b,c,d,e,f,g,
-b,c,d,e,f,g,h,
-a,b,c,d,e,f,g,
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/indirect_iterator.pdf b/doc/indirect_iterator.pdf deleted file mode 100755 index 3cdcbd9..0000000 Binary files a/doc/indirect_iterator.pdf and /dev/null differ diff --git a/doc/indirect_iterator.rst b/doc/indirect_iterator.rst deleted file mode 100644 index 91328e0..0000000 --- a/doc/indirect_iterator.rst +++ /dev/null @@ -1,34 +0,0 @@ -.. 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) - -+++++++++++++++++++ - Indirect Iterator -+++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: indirect_iterator_abstract.rst - -.. contents:: Table of Contents - -``indirect_iterator`` synopsis -.............................. - -.. include:: indirect_iterator_ref.rst -.. include:: indirect_iterator_eg.rst - -.. _iterator-category: iterator_facade.html#iterator-category -.. |iterator-category| replace:: *iterator-category* diff --git a/doc/indirect_iterator_abstract.rst b/doc/indirect_iterator_abstract.rst deleted file mode 100644 index 61fe016..0000000 --- a/doc/indirect_iterator_abstract.rst +++ /dev/null @@ -1,15 +0,0 @@ -.. 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) - -``indirect_iterator`` adapts an iterator by applying an -*extra* dereference inside of ``operator*()``. For example, this -iterator adaptor makes it possible to view a container of pointers -(e.g. ``list``) as if it were a container of the pointed-to type -(e.g. ``list``). ``indirect_iterator`` depends on two -auxiliary traits, ``pointee`` and ``indirect_reference``, to -provide support for underlying iterators whose ``value_type`` is -not an iterator. - - - diff --git a/doc/indirect_iterator_eg.rst b/doc/indirect_iterator_eg.rst deleted file mode 100644 index 1cb00c0..0000000 --- a/doc/indirect_iterator_eg.rst +++ /dev/null @@ -1,73 +0,0 @@ -.. 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) - -Example -....... - -This example prints an array of characters, using -``indirect_iterator`` to access the array of characters through an -array of pointers. Next ``indirect_iterator`` is used with the -``transform`` algorithm to copy the characters (incremented by one) to -another array. A constant indirect iterator is used for the source and -a mutable indirect iterator is used for the destination. The last part -of the example prints the original array of characters, but this time -using the ``make_indirect_iterator`` helper function. - - -:: - - char characters[] = "abcdefg"; - const int N = sizeof(characters)/sizeof(char) - 1; // -1 since characters has a null char - char* pointers_to_chars[N]; // at the end. - for (int i = 0; i < N; ++i) - pointers_to_chars[i] = &characters[i]; - - // Example of using indirect_iterator - - boost::indirect_iterator - indirect_first(pointers_to_chars), indirect_last(pointers_to_chars + N); - - std::copy(indirect_first, indirect_last, std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of making mutable and constant indirect iterators - - char mutable_characters[N]; - char* pointers_to_mutable_chars[N]; - for (int j = 0; j < N; ++j) - pointers_to_mutable_chars[j] = &mutable_characters[j]; - - boost::indirect_iterator mutable_indirect_first(pointers_to_mutable_chars), - mutable_indirect_last(pointers_to_mutable_chars + N); - boost::indirect_iterator const_indirect_first(pointers_to_chars), - const_indirect_last(pointers_to_chars + N); - - std::transform(const_indirect_first, const_indirect_last, - mutable_indirect_first, std::bind1st(std::plus(), 1)); - - std::copy(mutable_indirect_first, mutable_indirect_last, - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of using make_indirect_iterator() - - std::copy(boost::make_indirect_iterator(pointers_to_chars), - boost::make_indirect_iterator(pointers_to_chars + N), - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - -The output is:: - - a,b,c,d,e,f,g, - b,c,d,e,f,g,h, - a,b,c,d,e,f,g, - - -The source code for this example can be found `here`__. - -__ ../example/indirect_iterator_example.cpp - diff --git a/doc/indirect_iterator_ref.rst b/doc/indirect_iterator_ref.rst deleted file mode 100644 index d1430e1..0000000 --- a/doc/indirect_iterator_ref.rst +++ /dev/null @@ -1,181 +0,0 @@ -.. 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) - -:: - - template < - class Iterator - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator - { - public: - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - - indirect_iterator(); - indirect_iterator(Iterator x); - - template < - class Iterator2, class Value2, class Category2 - , class Reference2, class Difference2 - > - indirect_iterator( - indirect_iterator< - Iterator2, Value2, Category2, Reference2, Difference2 - > const& y - , typename enable_if_convertible::type* = 0 // exposition - ); - - Iterator const& base() const; - reference operator*() const; - indirect_iterator& operator++(); - indirect_iterator& operator--(); - private: - Iterator m_iterator; // exposition - }; - - -The member types of ``indirect_iterator`` are defined according to -the following pseudo-code, where ``V`` is -``iterator_traits::value_type`` - -.. parsed-literal:: - - if (Value is use_default) then - typedef remove_const::type>::type value_type; - else - typedef remove_const::type value_type; - - if (Reference is use_default) then - if (Value is use_default) then - typedef indirect_reference::type reference; - else - typedef Value& reference; - else - typedef Reference reference; - - if (Value is use_default) then - typedef pointee::type\* pointer; - else - typedef Value\* pointer; - - if (Difference is use_default) - typedef iterator_traits::difference_type difference_type; - else - typedef Difference difference_type; - - if (CategoryOrTraversal is use_default) - typedef *iterator-category* ( - iterator_traversal::type,``reference``,``value_type`` - ) iterator_category; - else - typedef *iterator-category* ( - CategoryOrTraversal,``reference``,``value_type`` - ) iterator_category; - - -``indirect_iterator`` requirements -.................................. - -The expression ``*v``, where ``v`` is an object of -``iterator_traits::value_type``, shall be valid -expression and convertible to ``reference``. ``Iterator`` shall -model the traversal concept indicated by ``iterator_category``. -``Value``, ``Reference``, and ``Difference`` shall be chosen so -that ``value_type``, ``reference``, and ``difference_type`` meet -the requirements indicated by ``iterator_category``. - -[Note: there are further requirements on the -``iterator_traits::value_type`` if the ``Value`` -parameter is not ``use_default``, as implied by the algorithm for -deducing the default for the ``value_type`` member.] - -``indirect_iterator`` models -............................ - -In addition to the concepts indicated by ``iterator_category`` -and by ``iterator_traversal::type``, a -specialization of ``indirect_iterator`` models the following -concepts, Where ``v`` is an object of -``iterator_traits::value_type``: - - * Readable Iterator if ``reference(*v)`` is convertible to - ``value_type``. - - * Writable Iterator if ``reference(*v) = t`` is a valid - expression (where ``t`` is an object of type - ``indirect_iterator::value_type``) - - * Lvalue Iterator if ``reference`` is a reference type. - -``indirect_iterator`` is interoperable with -``indirect_iterator`` if and only if ``X`` is -interoperable with ``Y``. - - -``indirect_iterator`` operations -................................ - -In addition to the operations required by the concepts described -above, specializations of ``indirect_iterator`` provide the -following operations. - - -``indirect_iterator();`` - -:Requires: ``Iterator`` must be Default Constructible. -:Effects: Constructs an instance of ``indirect_iterator`` with - a default-constructed ``m_iterator``. - - -``indirect_iterator(Iterator x);`` - -:Effects: Constructs an instance of ``indirect_iterator`` with - ``m_iterator`` copy constructed from ``x``. - -:: - - template < - class Iterator2, class Value2, unsigned Access, class Traversal - , class Reference2, class Difference2 - > - indirect_iterator( - indirect_iterator< - Iterator2, Value2, Access, Traversal, Reference2, Difference2 - > const& y - , typename enable_if_convertible::type* = 0 // exposition - ); - -:Requires: ``Iterator2`` is implicitly convertible to ``Iterator``. -:Effects: Constructs an instance of ``indirect_iterator`` whose - ``m_iterator`` subobject is constructed from ``y.base()``. - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - -``reference operator*() const;`` - -:Returns: ``**m_iterator`` - - -``indirect_iterator& operator++();`` - -:Effects: ``++m_iterator`` -:Returns: ``*this`` - - -``indirect_iterator& operator--();`` - -:Effects: ``--m_iterator`` -:Returns: ``*this`` diff --git a/doc/indirect_reference_ref.rst b/doc/indirect_reference_ref.rst deleted file mode 100755 index f222d7e..0000000 --- a/doc/indirect_reference_ref.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. Copyright David Abrahams 2004. Use, modification and distribution is -.. subject to 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) - -:: - - template - struct indirect_reference - { - typedef /* see below */ type; - }; - -:Requires: For an object ``x`` of type ``Dereferenceable``, ``*x`` - is well-formed. If ``++x`` is ill-formed it shall neither be - ambiguous nor shall it violate access control, and - ``pointee::type&`` shall be well-formed. - Otherwise ``iterator_traits::reference`` shall - be well formed. [Note: These requirements need not apply to - explicit or partial specializations of ``indirect_reference``] - -``type`` is determined according to the following algorithm, where -``x`` is an object of type ``Dereferenceable``:: - - if ( ++x is ill-formed ) - return ``pointee::type&`` - else - std::iterator_traits::reference - - \ No newline at end of file diff --git a/doc/interoperability-revisited.rst b/doc/interoperability-revisited.rst deleted file mode 100755 index add3546..0000000 --- a/doc/interoperability-revisited.rst +++ /dev/null @@ -1,235 +0,0 @@ -++++++++++++++++++++++++++++ - Interoperability Revisited -++++++++++++++++++++++++++++ - -:date: $Date$ -:copyright: Copyright Thomas Witt 2004. - -.. 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) - -Problem -======= - -The current iterator_facade specification makes it unneccessarily tedious to -implement interoperable iterators. - -In the following text a simplified example of the current iterator_facade specification is used to -illustrate the problem. - -In the current specification binary operators are implemented in the following way: - -template -struct Facade -{ -}; - -template -struct is_interoperable : - or_< - is_convertible - , is_convertible - > -{}; - -template< - class Derived1 - , class Derived2 -> -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - return static_cast(lhs).equal_to(static_cast -{ - bool equal_to(Mutable const&); -}; - -struct Constant : Facade -{ - Constant(); - Constant(Constant const&); - Constant(Mutable const&); - - ... - - bool equal_to(Constant const&); -}; - -Constant c; -Mutable m; - -c == m; // ok, dispatched to Constant::equal_to -m == c; // !! error, dispatched to Mutable::equal_to - -Instead the following "slightly" more complicated implementation is necessary - -struct Mutable : Facade -{ - template - enable_if || is_convertible, bool>::type equal_to(T const&); -}; - -struct Constant : Tag -{ - Constant(); - Constant(Constant const&); - Constant(Mutable const&); - - template - enable_if || is_convertible, bool>::type equal_to(T const&); -}; - -Beside the fact that the code is significantly more complex to understand and to teach there is -a major design problem lurking here. Note that in both types equal_to is a function template with -an unconstrained argument T. This is necessary so that further types can be made interoperable with -Mutable or Constant. Would Mutable be defined as - -struct Mutable : Facade -{ - bool equal_to(Mutable const&); - bool equal_to(Constant const&); -}; - -Constant and Mutable would still be interoperable but no further interoperable could be added -without changing Mutable. Even if this would be considered acceptable the current specification forces -a two way dependency between interoperable types. Note in the templated equal_to case this dependency -is implicitly created when specializing equal_to. - -Solution -======== - -The two way dependency can be avoided by enabling type conversion in the binary operator -implementation. Note that this is the usual way interoperability betwween types is achieved -for binary operators and one reason why binary operators are usually implemented as non-members. - -A simple implementation of this strategy would look like this - -template< - class T1 - , class T2 -> -struct interoperable_base : - if_< - is_convertible< - T2 - , T1 - > - , T1 - , T2> -{}; - - -template< - class Derived1 - , class Derived2 -> -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - typedef interoperable_base< - Derived1 - , Derived2 - >::type Base; - - return static_cast(lhs).equal_to(static_cast -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - return static_cast(lhs).equal_to(static_cast -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - return static_cast(rhs).equal_to(static_cast -{ - Constant(); - Constant(Constant const&); - Constant(Mutable const&); - - ... - - bool equal_to(Constant const&); - bool equal_to(Mutable const&); -}; - -c == m; // ok, dispatched to Constant::equal_to(Mutable const&), no conversion -m == c; // ok, dispatched to Constant::equal_to(Mutable const&), no conversion - -This definition of operator== introduces a possible ambiguity when both types are convertible -to each other. I don't think this is a problem as this behaviour is the same with concrete types. -I.e. - -struct A {}; - -bool operator==(A, A); - -struct B { B(A); }; - -bool operator==(B, B); - -A a; -B b(a); - -a == b; // error, ambiguous overload - -Effect -====== - -Iterator implementations using iterator_facade look exactly as if they were -"hand-implemented" (I am working on better wording). - -a) Less burden for the user - -b) The definition (standardese) of specialized adpters might be easier - (This has to be proved yet) diff --git a/doc/issues.rst b/doc/issues.rst deleted file mode 100755 index 5ddb61f..0000000 --- a/doc/issues.rst +++ /dev/null @@ -1,152 +0,0 @@ -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Problem with ``is_writable`` and ``is_swappable`` in N1550_ -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. _N1550: http://www.boost-consulting.com/writing/n1550.html -.. _N1530: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html - -:Author: David Abrahams and Jeremy Siek -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu -:Organization: `Boost Consulting`_, Indiana University Bloomington -:date: $Date$ -:Copyright: Copyright David Abrahams, Jeremy Siek 2003. Use, modification and - distribution is subject to 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) - -.. _`Boost Consulting`: http://www.boost-consulting.com - -.. contents:: Table of Contents - -============== - Introduction -============== - -The ``is_writable`` and ``is_swappable`` traits classes in N1550_ -provide a mechanism for determining at compile time if an iterator -type is a model of the new Writable Iterator and Swappable Iterator -concepts, analogous to ``iterator_traits::iterator_category`` -for the old iterator concepts. For backward compatibility, -``is_writable`` and ``is_swappable`` not only work with new -iterators, but they also are intended to work for old -iterators (iterators that meet the requirements for one of the -iterator concepts in the current standard). In the case of old -iterators, the writability and swapability is deduced based on the -``iterator_category`` and also the ``reference`` type. The -specification for this deduction gives false positives for forward -iterators that have non-assignable value types. - -To review, the part of the ``is_writable`` trait definition which -applies to old iterators is:: - - if (cat is convertible to output_iterator_tag) - return true; - else if (cat is convertible to forward_iterator_tag - and iterator_traits::reference is a - mutable reference) - return true; - else - return false; - -Suppose the ``value_type`` of the iterator ``It`` has a private -assignment operator:: - - class B { - public: - ... - private: - B& operator=(const B&); - }; - -and suppose the ``reference`` type of the iterator is ``B&``. In -that case, ``is_writable::value`` will be true when in fact -attempting to write into ``B`` will cause an error. - -The same problem applies to ``is_swappable``. - - -==================== - Proposed Resolution -==================== - -1. Remove the ``is_writable`` and ``is_swappable`` traits, and remove the - requirements in the Writable Iterator and Swappable Iterator concepts - that require their models to support these traits. - -2. Change the ``is_readable`` specification to be: - ``is_readable::type`` is ``true_type`` if the - result type of ``X::operator*`` is convertible to - ``iterator_traits::value_type`` and is ``false_type`` - otherwise. Also, ``is_readable`` is required to satisfy - the requirements for the UnaryTypeTrait concept - (defined in the type traits proposal). - - Remove the requirement for support of the ``is_readable`` trait from - the Readable Iterator concept. - - -3. Remove the ``iterator_tag`` class. - -4. Change the specification of ``traversal_category`` to:: - - traversal-category(Iterator) = - let cat = iterator_traits::iterator_category - if (cat is convertible to incrementable_iterator_tag) - return cat; // Iterator is a new iterator - else if (cat is convertible to random_access_iterator_tag) - return random_access_traversal_tag; - else if (cat is convertible to bidirectional_iterator_tag) - return bidirectional_traversal_tag; - else if (cat is convertible to forward_iterator_tag) - return forward_traversal_tag; - else if (cat is convertible to input_iterator_tag) - return single_pass_iterator_tag; - else if (cat is convertible to output_iterator_tag) - return incrementable_iterator_tag; - else - return null_category_tag; - - -========== - Rationale -========== - -1. There are two reasons for removing ``is_writable`` - and ``is_swappable``. The first is that we do not know of - a way to fix the specification so that it gives the correct - answer for all iterators. Second, there was only a weak - motivation for having ``is_writable`` and ``is_swappable`` - there in the first place. The main motivation was simply - uniformity: we have tags for the old iterator categories - so we should have tags for the new iterator categories. - While having tags and the capability to dispatch based - on the traversal categories is often used, we see - less of a need for dispatching based on writability - and swappability, since typically algorithms - that need these capabilities have no alternative if - they are not provided. - -2. We discovered that the ``is_readable`` trait can be implemented - using only the iterator type itself and its ``value_type``. - Therefore we remove the requirement for ``is_readable`` from the - Readable Iterator concept, and change the definition of - ``is_readable`` so that it works for any iterator type. - -3. The purpose of the ``iterator_tag`` class was to - bundle the traversal and access category tags - into the ``iterator_category`` typedef. - With ``is_writable`` and ``is_swappable`` gone, and - ``is_readable`` no longer in need of special hints, - there is no reason for iterators to provide - information about the access capabilities of an iterator. - Thus there is no need for the ``iterator_tag``. The - traversal tag can be directly used for the - ``iterator_category``. If a new iterator is intended to be backward - compatible with old iterator concepts, a tag type - that is convertible to both one of the new traversal tags - and also to an old iterator tag can be created and use - for the ``iterator_category``. - -4. The changes to the specification of ``traversal_category`` are a - direct result of the removal of ``iterator_tag``. - diff --git a/doc/iterator_adaptor.html b/doc/iterator_adaptor.html deleted file mode 100644 index 1a559d7..0000000 --- a/doc/iterator_adaptor.html +++ /dev/null @@ -1,737 +0,0 @@ - - - - - - -Iterator Adaptor - - - - - - - -
-

Iterator Adaptor

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract:
- - - - - -

Each specialization of the iterator_adaptor class template is derived from -a specialization of iterator_facade. The core interface functions -expected by iterator_facade are implemented in terms of the -iterator_adaptor's Base template parameter. A class derived -from iterator_adaptor typically redefines some of the core -interface functions to adapt the behavior of the Base type. -Whether the derived class models any of the standard iterator concepts -depends on the operations supported by the Base type and which -core interface functions of iterator_facade are redefined in the -Derived class.

- -
-

Overview

- - - - - -

The iterator_adaptor class template adapts some Base [1] -type to create a new iterator. Instantiations of iterator_adaptor -are derived from a corresponding instantiation of iterator_facade -and implement the core behaviors in terms of the Base type. In -essence, iterator_adaptor merely forwards all operations to an -instance of the Base type, which it stores as a member.

- - - - - -
[1](1, 2) The term "Base" here does not refer to a base class and is -not meant to imply the use of derivation. We have followed the lead -of the standard library, which provides a base() function to access -the underlying iterator object of a reverse_iterator adaptor.
-

The user of iterator_adaptor creates a class derived from an -instantiation of iterator_adaptor and then selectively -redefines some of the core member functions described in the -iterator_facade core requirements table. The Base type need -not meet the full requirements for an iterator; it need only -support the operations used by the core interface functions of -iterator_adaptor that have not been redefined in the user's -derived class.

-

Several of the template parameters of iterator_adaptor default -to use_default. This allows the -user to make use of a default parameter even when she wants to -specify a parameter later in the parameter list. Also, the -defaults for the corresponding associated types are somewhat -complicated, so metaprogramming is required to compute them, and -use_default can help to simplify the implementation. Finally, -the identity of the use_default type is not left unspecified -because specification helps to highlight that the Reference -template parameter may not always be identical to the iterator's -reference type, and will keep users from making mistakes based on -that assumption.

-
-
-

Reference

- - - - - -
-template <
-    class Derived
-  , class Base
-  , class Value               = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference           = use_default
-  , class Difference = use_default
->
-class iterator_adaptor
-  : public iterator_facade<Derived, V', C', R', D'> // see details
-{
-    friend class iterator_core_access;
- public:
-    iterator_adaptor();
-    explicit iterator_adaptor(Base const& iter);
-    typedef Base base_type;
-    Base const& base() const;
- protected:
-    typedef iterator_adaptor iterator_adaptor_;
-    Base const& base_reference() const;
-    Base& base_reference();
- private: // Core iterator interface for iterator_facade.
-    typename iterator_adaptor::reference dereference() const;
-
-    template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >
-    bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
-    void advance(typename iterator_adaptor::difference_type n);
-    void increment();
-    void decrement();
-
-    template <
-        class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >
-    typename iterator_adaptor::difference_type distance_to(
-        iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- private:
-    Base m_iterator; // exposition only
-};
-
-
-

iterator_adaptor requirements

-

static_cast<Derived*>(iterator_adaptor*) shall be well-formed. -The Base argument shall be Assignable and Copy Constructible.

-
-
-

iterator_adaptor base class parameters

-

The V', C', R', and D' parameters of the iterator_facade -used as a base class in the summary of iterator_adaptor -above are defined as follows:

-
-V' = if (Value is use_default)
-          return iterator_traits<Base>::value_type
-      else
-          return Value
-
-C' = if (CategoryOrTraversal is use_default)
-          return iterator_traversal<Base>::type
-      else
-          return CategoryOrTraversal
-
-R' = if (Reference is use_default)
-          if (Value is use_default)
-              return iterator_traits<Base>::reference
-          else
-              return Value&
-      else
-          return Reference
-
-D' = if (Difference is use_default)
-          return iterator_traits<Base>::difference_type
-      else
-          return Difference
-
- - - -
-
-

iterator_adaptor public operations

-

iterator_adaptor();

- --- - - - - - -
Requires:The Base type must be Default Constructible.
Returns:An instance of iterator_adaptor with -m_iterator default constructed.
-

explicit iterator_adaptor(Base const& iter);

- --- - - - -
Returns:An instance of iterator_adaptor with -m_iterator copy constructed from iter.
-

Base const& base() const;

- --- - - - -
Returns:m_iterator
-
-
-

iterator_adaptor protected member functions

-

Base const& base_reference() const;

- --- - - - -
Returns:A const reference to m_iterator.
-

Base& base_reference();

- --- - - - -
Returns:A non-const reference to m_iterator.
-
-
-

iterator_adaptor private member functions

-

typename iterator_adaptor::reference dereference() const;

- --- - - - -
Returns:*m_iterator
-
-template <
-class OtherDerived, class OtherIterator, class V, class C, class R, class D
->
-bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
- --- - - - -
Returns:m_iterator == x.base()
-

void advance(typename iterator_adaptor::difference_type n);

- --- - - - -
Effects:m_iterator += n;
-

void increment();

- --- - - - -
Effects:++m_iterator;
-

void decrement();

- --- - - - -
Effects:--m_iterator;
-
-template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
->
-typename iterator_adaptor::difference_type distance_to(
-    iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- --- - - - -
Returns:y.base() - m_iterator
-
-
-
-

Tutorial Example

- - - -

In this section we'll further refine the node_iter class -template we developed in the iterator_facade tutorial. If you haven't already -read that material, you should go back now and check it out because -we're going to pick up right where it left off.

- -

You probably didn't think of it this way, but the node_base* -object that underlies node_iterator is itself an iterator, -just like all other pointers. If we examine that pointer closely -from an iterator perspective, we can see that it has much in common -with the node_iterator we're building. First, they share most -of the same associated types (value_type, reference, -pointer, and difference_type). Second, even some of the -core functionality is the same: operator* and operator== on -the node_iterator return the result of invoking the same -operations on the underlying pointer, via the node_iterator's -dereference and equal member functions). The only real behavioral difference -between node_base* and node_iterator can be observed when -they are incremented: node_iterator follows the -m_next pointer, while node_base* just applies an address offset.

-

It turns out that the pattern of building an iterator on another -iterator-like type (the Base [1] type) while modifying -just a few aspects of the underlying type's behavior is an -extremely common one, and it's the pattern addressed by -iterator_adaptor. Using iterator_adaptor is very much like -using iterator_facade, but because iterator_adaptor tries to -mimic as much of the Base type's behavior as possible, we -neither have to supply a Value argument, nor implement any core -behaviors other than increment. The implementation of -node_iter is thus reduced to:

-
-template <class Value>
-class node_iter
-  : public boost::iterator_adaptor<
-        node_iter<Value>                // Derived
-      , Value*                          // Base
-      , boost::use_default              // Value
-      , boost::forward_traversal_tag    // CategoryOrTraversal
-    >
-{
- private:
-    struct enabler {};  // a private type avoids misuse
-
- public:
-    node_iter()
-      : node_iter::iterator_adaptor_(0) {}
-
-    explicit node_iter(Value* p)
-      : node_iter::iterator_adaptor_(p) {}
-
-    template <class OtherValue>
-    node_iter(
-        node_iter<OtherValue> const& other
-      , typename boost::enable_if<
-            boost::is_convertible<OtherValue*,Value*>
-          , enabler
-        >::type = enabler()
-    )
-      : node_iter::iterator_adaptor_(other.base()) {}
-
- private:
-    friend class boost::iterator_core_access;
-    void increment() { this->base_reference() = this->base()->next(); }
-};
-
-

Note the use of node_iter::iterator_adaptor_ here: because -iterator_adaptor defines a nested iterator_adaptor_ type -that refers to itself, that gives us a convenient way to refer to -the complicated base class type of node_iter<Value>. [Note: -this technique is known not to work with Borland C++ 5.6.4 and -Metrowerks CodeWarrior versions prior to 9.0]

-

You can see an example program that exercises this version of the -node iterators here.

-

In the case of node_iter, it's not very compelling to pass -boost::use_default as iterator_adaptor's Value -argument; we could have just passed node_iter's Value -along to iterator_adaptor, and that'd even be shorter! Most -iterator class templates built with iterator_adaptor are -parameterized on another iterator type, rather than on its -value_type. For example, boost::reverse_iterator takes an -iterator type argument and reverses its direction of traversal, -since the original iterator and the reversed one have all the same -associated types, iterator_adaptor's delegation of default -types to its Base saves the implementor of -boost::reverse_iterator from writing:

-
-std::iterator_traits<Iterator>::some-associated-type
-
-

at least four times.

-

We urge you to review the documentation and implementations of -reverse_iterator and the other Boost specialized iterator -adaptors to get an idea of the sorts of things you can do with -iterator_adaptor. In particular, have a look at -transform_iterator, which is perhaps the most straightforward -adaptor, and also counting_iterator, which demonstrates that -iterator_adaptor's Base type needn't be an iterator.

-
-
- - diff --git a/doc/iterator_adaptor.pdf b/doc/iterator_adaptor.pdf deleted file mode 100755 index 24582c1..0000000 Binary files a/doc/iterator_adaptor.pdf and /dev/null differ diff --git a/doc/iterator_adaptor.rst b/doc/iterator_adaptor.rst deleted file mode 100644 index 4f8ca01..0000000 --- a/doc/iterator_adaptor.rst +++ /dev/null @@ -1,41 +0,0 @@ -.. 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) - -+++++++++++++++++ - Iterator Adaptor -+++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - -.. include:: iterator_adaptor_abstract.rst - -.. contents:: Table of Contents - -Overview -======== - -.. include:: iterator_adaptor_body.rst - - -Reference -========= - -.. include:: iterator_adaptor_ref.rst - -Tutorial Example -================ - -.. include:: iterator_adaptor_tutorial.rst diff --git a/doc/iterator_adaptor_abstract.rst b/doc/iterator_adaptor_abstract.rst deleted file mode 100644 index fa887f2..0000000 --- a/doc/iterator_adaptor_abstract.rst +++ /dev/null @@ -1,19 +0,0 @@ -.. 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) - -.. Version 1.1 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -Each specialization of the ``iterator_adaptor`` class template is derived from -a specialization of ``iterator_facade``. The core interface functions -expected by ``iterator_facade`` are implemented in terms of the -``iterator_adaptor``\ 's ``Base`` template parameter. A class derived -from ``iterator_adaptor`` typically redefines some of the core -interface functions to adapt the behavior of the ``Base`` type. -Whether the derived class models any of the standard iterator concepts -depends on the operations supported by the ``Base`` type and which -core interface functions of ``iterator_facade`` are redefined in the -``Derived`` class. diff --git a/doc/iterator_adaptor_body.rst b/doc/iterator_adaptor_body.rst deleted file mode 100644 index ddd7f7b..0000000 --- a/doc/iterator_adaptor_body.rst +++ /dev/null @@ -1,43 +0,0 @@ -.. 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) - -.. Version 1.2 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -The ``iterator_adaptor`` class template adapts some ``Base`` [#base]_ -type to create a new iterator. Instantiations of ``iterator_adaptor`` -are derived from a corresponding instantiation of ``iterator_facade`` -and implement the core behaviors in terms of the ``Base`` type. In -essence, ``iterator_adaptor`` merely forwards all operations to an -instance of the ``Base`` type, which it stores as a member. - -.. [#base] The term "Base" here does not refer to a base class and is - not meant to imply the use of derivation. We have followed the lead - of the standard library, which provides a base() function to access - the underlying iterator object of a ``reverse_iterator`` adaptor. - -The user of ``iterator_adaptor`` creates a class derived from an -instantiation of ``iterator_adaptor`` and then selectively -redefines some of the core member functions described in the -``iterator_facade`` core requirements table. The ``Base`` type need -not meet the full requirements for an iterator; it need only -support the operations used by the core interface functions of -``iterator_adaptor`` that have not been redefined in the user's -derived class. - -Several of the template parameters of ``iterator_adaptor`` default -to ``use_default``. This allows the -user to make use of a default parameter even when she wants to -specify a parameter later in the parameter list. Also, the -defaults for the corresponding associated types are somewhat -complicated, so metaprogramming is required to compute them, and -``use_default`` can help to simplify the implementation. Finally, -the identity of the ``use_default`` type is not left unspecified -because specification helps to highlight that the ``Reference`` -template parameter may not always be identical to the iterator's -``reference`` type, and will keep users from making mistakes based on -that assumption. - diff --git a/doc/iterator_adaptor_ref.rst b/doc/iterator_adaptor_ref.rst deleted file mode 100644 index 50c00fc..0000000 --- a/doc/iterator_adaptor_ref.rst +++ /dev/null @@ -1,182 +0,0 @@ -.. 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) - -.. Version 1.4 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. parsed-literal:: - - template < - class Derived - , class Base - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor - : public iterator_facade // see details__ - { - friend class iterator_core_access; - public: - iterator_adaptor(); - explicit iterator_adaptor(Base const& iter); - typedef Base base_type; - Base const& base() const; - protected: - typedef iterator_adaptor iterator_adaptor\_; - Base const& base_reference() const; - Base& base_reference(); - private: // Core iterator interface for iterator_facade. - typename iterator_adaptor::reference dereference() const; - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - bool equal(iterator_adaptor const& x) const; - - void advance(typename iterator_adaptor::difference_type n); - void increment(); - void decrement(); - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - typename iterator_adaptor::difference_type distance_to( - iterator_adaptor const& y) const; - - private: - Base m_iterator; // exposition only - }; - -__ base_parameters_ - -.. _requirements: - -``iterator_adaptor`` requirements ---------------------------------- - -``static_cast(iterator_adaptor*)`` shall be well-formed. -The ``Base`` argument shall be Assignable and Copy Constructible. - - -.. _base_parameters: - -``iterator_adaptor`` base class parameters ------------------------------------------- - -The *V'*, *C'*, *R'*, and *D'* parameters of the ``iterator_facade`` -used as a base class in the summary of ``iterator_adaptor`` -above are defined as follows: - -.. parsed-literal:: - - *V'* = if (Value is use_default) - return iterator_traits::value_type - else - return Value - - *C'* = if (CategoryOrTraversal is use_default) - return iterator_traversal::type - else - return CategoryOrTraversal - - *R'* = if (Reference is use_default) - if (Value is use_default) - return iterator_traits::reference - else - return Value& - else - return Reference - - *D'* = if (Difference is use_default) - return iterator_traits::difference_type - else - return Difference - -.. ``iterator_adaptor`` models - --------------------------- - - In order for ``Derived`` to model the iterator concepts corresponding - to ``iterator_traits::iterator_category``, the expressions - involving ``m_iterator`` in the specifications of those private member - functions of ``iterator_adaptor`` that may be called by - ``iterator_facade`` in evaluating any valid - expression involving ``Derived`` in those concepts' requirements. - -.. The above is confusing and needs a rewrite. -JGS -.. That's why it's removed. We're embracing inheritance, remember? - -``iterator_adaptor`` public operations --------------------------------------- - -``iterator_adaptor();`` - -:Requires: The ``Base`` type must be Default Constructible. -:Returns: An instance of ``iterator_adaptor`` with - ``m_iterator`` default constructed. - - -``explicit iterator_adaptor(Base const& iter);`` - -:Returns: An instance of ``iterator_adaptor`` with - ``m_iterator`` copy constructed from ``iter``. - -``Base const& base() const;`` - -:Returns: ``m_iterator`` - -``iterator_adaptor`` protected member functions ------------------------------------------------ - -``Base const& base_reference() const;`` - -:Returns: A const reference to ``m_iterator``. - - -``Base& base_reference();`` - -:Returns: A non-const reference to ``m_iterator``. - - -``iterator_adaptor`` private member functions ---------------------------------------------- - -``typename iterator_adaptor::reference dereference() const;`` - -:Returns: ``*m_iterator`` - -:: - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - bool equal(iterator_adaptor const& x) const; - -:Returns: ``m_iterator == x.base()`` - - -``void advance(typename iterator_adaptor::difference_type n);`` - -:Effects: ``m_iterator += n;`` - -``void increment();`` - -:Effects: ``++m_iterator;`` - -``void decrement();`` - -:Effects: ``--m_iterator;`` - -:: - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - typename iterator_adaptor::difference_type distance_to( - iterator_adaptor const& y) const; - -:Returns: ``y.base() - m_iterator`` diff --git a/doc/iterator_adaptor_tutorial.rst b/doc/iterator_adaptor_tutorial.rst deleted file mode 100755 index 4106846..0000000 --- a/doc/iterator_adaptor_tutorial.rst +++ /dev/null @@ -1,135 +0,0 @@ -.. Copyright David Abrahams 2004. Use, modification and distribution is -.. subject to 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) - -In this section we'll further refine the ``node_iter`` class -template we developed in the |fac_tut|_. If you haven't already -read that material, you should go back now and check it out because -we're going to pick up right where it left off. - -.. |fac_tut| replace:: ``iterator_facade`` tutorial -.. _fac_tut: iterator_facade.html#tutorial-example - -.. sidebar:: ``node_base*`` really *is* an iterator - - It's not really a very interesting iterator, since ``node_base`` - is an abstract class: a pointer to a ``node_base`` just points - at some base subobject of an instance of some other class, and - incrementing a ``node_base*`` moves it past this base subobject - to who-knows-where? The most we can do with that incremented - position is to compare another ``node_base*`` to it. In other - words, the original iterator traverses a one-element array. - -You probably didn't think of it this way, but the ``node_base*`` -object that underlies ``node_iterator`` is itself an iterator, -just like all other pointers. If we examine that pointer closely -from an iterator perspective, we can see that it has much in common -with the ``node_iterator`` we're building. First, they share most -of the same associated types (``value_type``, ``reference``, -``pointer``, and ``difference_type``). Second, even some of the -core functionality is the same: ``operator*`` and ``operator==`` on -the ``node_iterator`` return the result of invoking the same -operations on the underlying pointer, via the ``node_iterator``\ 's -|dereference_and_equal|_). The only real behavioral difference -between ``node_base*`` and ``node_iterator`` can be observed when -they are incremented: ``node_iterator`` follows the -``m_next`` pointer, while ``node_base*`` just applies an address offset. - -.. |dereference_and_equal| replace:: ``dereference`` and ``equal`` member functions -.. _dereference_and_equal: iterator_facade.html#implementing-the-core-operations - -It turns out that the pattern of building an iterator on another -iterator-like type (the ``Base`` [#base]_ type) while modifying -just a few aspects of the underlying type's behavior is an -extremely common one, and it's the pattern addressed by -``iterator_adaptor``. Using ``iterator_adaptor`` is very much like -using ``iterator_facade``, but because iterator_adaptor tries to -mimic as much of the ``Base`` type's behavior as possible, we -neither have to supply a ``Value`` argument, nor implement any core -behaviors other than ``increment``. The implementation of -``node_iter`` is thus reduced to:: - - template - class node_iter - : public boost::iterator_adaptor< - node_iter // Derived - , Value* // Base - , boost::use_default // Value - , boost::forward_traversal_tag // CategoryOrTraversal - > - { - private: - struct enabler {}; // a private type avoids misuse - - public: - node_iter() - : node_iter::iterator_adaptor_(0) {} - - explicit node_iter(Value* p) - : node_iter::iterator_adaptor_(p) {} - - template - node_iter( - node_iter const& other - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() - ) - : node_iter::iterator_adaptor_(other.base()) {} - - private: - friend class boost::iterator_core_access; - void increment() { this->base_reference() = this->base()->next(); } - }; - -Note the use of ``node_iter::iterator_adaptor_`` here: because -``iterator_adaptor`` defines a nested ``iterator_adaptor_`` type -that refers to itself, that gives us a convenient way to refer to -the complicated base class type of ``node_iter``. [Note: -this technique is known not to work with Borland C++ 5.6.4 and -Metrowerks CodeWarrior versions prior to 9.0] - -You can see an example program that exercises this version of the -node iterators `here`__. - -__ ../example/node_iterator3.cpp - -In the case of ``node_iter``, it's not very compelling to pass -``boost::use_default`` as ``iterator_adaptor``\ 's ``Value`` -argument; we could have just passed ``node_iter``\ 's ``Value`` -along to ``iterator_adaptor``, and that'd even be shorter! Most -iterator class templates built with ``iterator_adaptor`` are -parameterized on another iterator type, rather than on its -``value_type``. For example, ``boost::reverse_iterator`` takes an -iterator type argument and reverses its direction of traversal, -since the original iterator and the reversed one have all the same -associated types, ``iterator_adaptor``\ 's delegation of default -types to its ``Base`` saves the implementor of -``boost::reverse_iterator`` from writing: - -.. parsed-literal:: - - std::iterator_traits::*some-associated-type* - -at least four times. - -We urge you to review the documentation and implementations of -|reverse_iterator|_ and the other Boost `specialized iterator -adaptors`__ to get an idea of the sorts of things you can do with -``iterator_adaptor``. In particular, have a look at -|transform_iterator|_, which is perhaps the most straightforward -adaptor, and also |counting_iterator|_, which demonstrates that -``iterator_adaptor``\ 's ``Base`` type needn't be an iterator. - -.. |reverse_iterator| replace:: ``reverse_iterator`` -.. _reverse_iterator: reverse_iterator.html - -.. |counting_iterator| replace:: ``counting_iterator`` -.. _counting_iterator: counting_iterator.html - -.. |transform_iterator| replace:: ``transform_iterator`` -.. _transform_iterator: transform_iterator.html - -__ index.html#specialized-adaptors - diff --git a/doc/iterator_archetypes.html b/doc/iterator_archetypes.html deleted file mode 100755 index 323a214..0000000 --- a/doc/iterator_archetypes.html +++ /dev/null @@ -1,500 +0,0 @@ - - - - - - -Iterator Archetype - - - - - - - -
-

Iterator Archetype

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
Organization:Boost Consulting, Indiana University Open Systems -Lab, Zephyr Associates, Inc.
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2004.
- - - - --- - - - -
abstract:The iterator_archetype class constructs a minimal implementation of -one of the iterator access concepts and one of the iterator traversal concepts. -This is used for doing a compile-time check to see if a the type requirements -of a template are really enough to cover the implementation of the template. -For further information see the documentation for the boost::concept_check library.
- -
-

Reference

-
-

iterator_archetype Synopsis

-
-namespace iterator_archetypes
-{
-    // Access categories
-
-    typedef /*implementation  defined*/ readable_iterator_t;
-    typedef /*implementation  defined*/ writable_iterator_t;
-    typedef /*implementation  defined*/ readable_writable_iterator_t;
-    typedef /*implementation  defined*/ readable_lvalue_iterator_t;
-    typedef /*implementation  defined*/ writable_lvalue_iterator_t;
-
-}
-
-template <
-    class Value
-  , class AccessCategory
-  , class TraversalCategory
->
-class iterator_archetype
-{
-    typedef /* see below */ value_type;
-    typedef /* see below */ reference;
-    typedef /* see below */ pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-};
-
-
-
-

Access Category Tags

-

The access category types provided correspond to the following -standard iterator access concept combinations:

-
-readable_iterator_t :=
-
-  Readable Iterator
-
-writable_iterator_t :=
-
-  Writeable Iterator
-
-readable_writable_iterator_t :=
-
-  Readable Iterator & Writeable Iterator & Swappable Iterator
-
-readable_lvalue_iterator_t :=
-
-  Readable Iterator & Lvalue Iterator
-
-writeable_lvalue_iterator_t :=
-
-  Readable Iterator & Writeable Iterator & Swappable Iterator & Lvalue Iterator
-
-
-
-

iterator_archetype Requirements

-

The AccessCategory argument must be one of the predefined access -category tags. The TraversalCategory must be one of the standard -traversal tags. The Value type must satisfy the requirements of -the iterator concept specified by AccessCategory and -TraversalCategory as implied by the nested traits types.

-
-
-

iterator_archetype Models

-

iterator_archetype models the iterator concepts specified by the -AccessCategory and TraversalCategory -arguments. iterator_archetype does not model any other access -concepts or any more derived traversal concepts.

-
-
-

Traits

-

The nested trait types are defined as follows:

-
-if (AccessCategory == readable_iterator_t)
-
-  value_type = Value
-  reference  = Value
-  pointer    = Value*
-
-else if (AccessCategory == writable_iterator_t)
-
-  value_type = void
-  reference  = void
-  pointer    = void
-
-else if (AccessCategory == readable_writable_iterator_t)
-
-  value_type = Value
-
-  reference :=
-
-    A type X that is convertible to Value for which the following
-    expression is valid. Given an object x of type X and v of type
-    Value.
-
-    x = v
-
-  pointer    = Value*
-
-else if (AccessCategory == readable_lvalue_iterator_t)
-
-  value_type = Value
-  reference  = Value const&
-  pointer    = Value const*
-
-else if (AccessCategory == writable_lvalue_iterator_t)
-
-  value_type = Value
-  reference  = Value&
-  pointer    = Value*
-
-if ( TraversalCategory is convertible to forward_traversal_tag )
-
-  difference_type := ptrdiff_t
-
-else
-
-  difference_type := unspecified type
-
-
-iterator_category :=
-
-  A type X satisfying the following two constraints:
-
-     1. X is convertible to X1, and not to any more-derived
-        type, where X1 is defined by:
-
-          if (reference is a reference type
-              && TraversalCategory is convertible to forward_traversal_tag)
-          {
-              if (TraversalCategory is convertible to random_access_traversal_tag)
-                  X1 = random_access_iterator_tag
-              else if (TraversalCategory is convertible to bidirectional_traversal_tag)
-                  X1 = bidirectional_iterator_tag
-              else
-                  X1 = forward_iterator_tag
-          }
-          else
-          {
-              if (TraversalCategory is convertible to single_pass_traversal_tag
-                  && reference != void)
-                  X1 = input_iterator_tag
-              else
-                  X1 = output_iterator_tag
-          }
-
-     2. X is convertible to TraversalCategory
-
-
-
-
- - diff --git a/doc/iterator_archetypes.pdf b/doc/iterator_archetypes.pdf deleted file mode 100755 index 8cecde3..0000000 Binary files a/doc/iterator_archetypes.pdf and /dev/null differ diff --git a/doc/iterator_archetypes.rst b/doc/iterator_archetypes.rst deleted file mode 100755 index 827723b..0000000 --- a/doc/iterator_archetypes.rst +++ /dev/null @@ -1,193 +0,0 @@ -.. 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) - -++++++++++++++++++++ - Iterator Archetype -++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2004. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:abstract: The ``iterator_archetype`` class constructs a minimal implementation of - one of the iterator access concepts and one of the iterator traversal concepts. - This is used for doing a compile-time check to see if a the type requirements - of a template are really enough to cover the implementation of the template. - For further information see the documentation for the |concepts|_ library. - -.. |concepts| replace:: ``boost::concept_check`` -.. _concepts: ../../concept_check/index.html - - -.. contents:: Table of Contents - -Reference -========= - -``iterator_archetype`` Synopsis -............................... - -:: - - namespace iterator_archetypes - { - // Access categories - - typedef /*implementation defined*/ readable_iterator_t; - typedef /*implementation defined*/ writable_iterator_t; - typedef /*implementation defined*/ readable_writable_iterator_t; - typedef /*implementation defined*/ readable_lvalue_iterator_t; - typedef /*implementation defined*/ writable_lvalue_iterator_t; - - } - - template < - class Value - , class AccessCategory - , class TraversalCategory - > - class iterator_archetype - { - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - }; - -``Access Category Tags`` -........................ - -The access category types provided correspond to the following -standard iterator access concept combinations: - -:: - - readable_iterator_t := - - Readable Iterator - - writable_iterator_t := - - Writeable Iterator - - readable_writable_iterator_t := - - Readable Iterator & Writeable Iterator & Swappable Iterator - - readable_lvalue_iterator_t := - - Readable Iterator & Lvalue Iterator - - writeable_lvalue_iterator_t := - - Readable Iterator & Writeable Iterator & Swappable Iterator & Lvalue Iterator - -``iterator_archetype`` Requirements -................................... - -The ``AccessCategory`` argument must be one of the predefined access -category tags. The ``TraversalCategory`` must be one of the standard -traversal tags. The ``Value`` type must satisfy the requirements of -the iterator concept specified by ``AccessCategory`` and -``TraversalCategory`` as implied by the nested traits types. - -``iterator_archetype`` Models -............................. - -``iterator_archetype`` models the iterator concepts specified by the -``AccessCategory`` and ``TraversalCategory`` -arguments. ``iterator_archetype`` does not model any other access -concepts or any more derived traversal concepts. - -``Traits`` -.......... - -The nested trait types are defined as follows: - -:: - - if (AccessCategory == readable_iterator_t) - - value_type = Value - reference = Value - pointer = Value* - - else if (AccessCategory == writable_iterator_t) - - value_type = void - reference = void - pointer = void - - else if (AccessCategory == readable_writable_iterator_t) - - value_type = Value - - reference := - - A type X that is convertible to Value for which the following - expression is valid. Given an object x of type X and v of type - Value. - - x = v - - pointer = Value* - - else if (AccessCategory == readable_lvalue_iterator_t) - - value_type = Value - reference = Value const& - pointer = Value const* - - else if (AccessCategory == writable_lvalue_iterator_t) - - value_type = Value - reference = Value& - pointer = Value* - - if ( TraversalCategory is convertible to forward_traversal_tag ) - - difference_type := ptrdiff_t - - else - - difference_type := unspecified type - - - iterator_category := - - A type X satisfying the following two constraints: - - 1. X is convertible to X1, and not to any more-derived - type, where X1 is defined by: - - if (reference is a reference type - && TraversalCategory is convertible to forward_traversal_tag) - { - if (TraversalCategory is convertible to random_access_traversal_tag) - X1 = random_access_iterator_tag - else if (TraversalCategory is convertible to bidirectional_traversal_tag) - X1 = bidirectional_iterator_tag - else - X1 = forward_iterator_tag - } - else - { - if (TraversalCategory is convertible to single_pass_traversal_tag - && reference != void) - X1 = input_iterator_tag - else - X1 = output_iterator_tag - } - - 2. X is convertible to TraversalCategory - - diff --git a/doc/iterator_concepts.html b/doc/iterator_concepts.html deleted file mode 100644 index 2bcb2e7..0000000 --- a/doc/iterator_concepts.html +++ /dev/null @@ -1,403 +0,0 @@ - - - - - - -Iterator Concepts - - - - - - - -
-

Iterator Concepts

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
Organization:Boost Consulting, Indiana University Open Systems -Lab, Zephyr Associates, Inc.
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2004.
- - - - --- - - - -
abstract:The iterator concept checking classes provide a mechanism for -a template to report better error messages when a user instantiates -the template with a type that does not meet the requirements of -the template.
-

For an introduction to using concept checking classes, see -the documentation for the boost::concept_check library.

-
-

Reference

- - -
-

iterator_concepts.hpp Synopsis

-
-namespace boost_concepts {
-
-    // Iterator Access Concepts
-
-    template <typename Iterator>
-    class ReadableIteratorConcept;
-
-    template <
-        typename Iterator
-      , typename ValueType = std::iterator_traits<Iterator>::value_type
-    >
-    class WritableIteratorConcept;
-
-    template <typename Iterator>
-    class SwappableIteratorConcept;
-
-    template <typename Iterator>
-    class LvalueIteratorConcept;
-
-    // Iterator Traversal Concepts
-
-    template <typename Iterator>
-    class IncrementableIteratorConcept;
-
-    template <typename Iterator>
-    class SinglePassIteratorConcept;
-
-    template <typename Iterator>
-    class ForwardTraversalConcept;
-
-    template <typename Iterator>
-    class BidirectionalTraversalConcept;
-
-    template <typename Iterator>
-    class RandomAccessTraversalConcept;
-
-    // Interoperability
-
-    template <typename Iterator, typename ConstIterator>
-    class InteroperableIteratorConcept;
-
-}
-
-
-
-
- - diff --git a/doc/iterator_concepts.pdf b/doc/iterator_concepts.pdf deleted file mode 100755 index 98e4302..0000000 Binary files a/doc/iterator_concepts.pdf and /dev/null differ diff --git a/doc/iterator_concepts.rst b/doc/iterator_concepts.rst deleted file mode 100755 index 77242a4..0000000 --- a/doc/iterator_concepts.rst +++ /dev/null @@ -1,130 +0,0 @@ -.. 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) - -++++++++++++++++++ - Iterator Concepts -++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2004. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:abstract: The iterator concept checking classes provide a mechanism for - a template to report better error messages when a user instantiates - the template with a type that does not meet the requirements of - the template. - - -For an introduction to using concept checking classes, see -the documentation for the |concepts|_ library. - -.. |concepts| replace:: ``boost::concept_check`` -.. _concepts: ../../concept_check/index.html - - -Reference -========= - -Iterator Access Concepts -........................ - -* |Readable|_ -* |Writable|_ -* |Swappable|_ -* |Lvalue|_ - -.. |Readable| replace:: *Readable Iterator* -.. _Readable: ReadableIterator.html - -.. |Writable| replace:: *Writable Iterator* -.. _Writable: WritableIterator.html - -.. |Swappable| replace:: *Swappable Iterator* -.. _Swappable: SwappableIterator.html - -.. |Lvalue| replace:: *Lvalue Iterator* -.. _Lvalue: LvalueIterator.html - - -Iterator Traversal Concepts -........................... - -* |Incrementable|_ -* |SinglePass|_ -* |Forward|_ -* |Bidir|_ -* |Random|_ - - -.. |Incrementable| replace:: *Incrementable Iterator* -.. _Incrementable: IncrementableIterator.html - -.. |SinglePass| replace:: *Single Pass Iterator* -.. _SinglePass: SinglePassIterator.html - -.. |Forward| replace:: *Forward Traversal* -.. _Forward: ForwardTraversal.html - -.. |Bidir| replace:: *Bidirectional Traversal* -.. _Bidir: BidirectionalTraversal.html - -.. |Random| replace:: *Random Access Traversal* -.. _Random: RandomAccessTraversal.html - - - -``iterator_concepts.hpp`` Synopsis -.................................. - -:: - - namespace boost_concepts { - - // Iterator Access Concepts - - template - class ReadableIteratorConcept; - - template < - typename Iterator - , typename ValueType = std::iterator_traits::value_type - > - class WritableIteratorConcept; - - template - class SwappableIteratorConcept; - - template - class LvalueIteratorConcept; - - // Iterator Traversal Concepts - - template - class IncrementableIteratorConcept; - - template - class SinglePassIteratorConcept; - - template - class ForwardTraversalConcept; - - template - class BidirectionalTraversalConcept; - - template - class RandomAccessTraversalConcept; - - // Interoperability - - template - class InteroperableIteratorConcept; - - } diff --git a/doc/iterator_facade.html b/doc/iterator_facade.html deleted file mode 100644 index 10fdc34..0000000 --- a/doc/iterator_facade.html +++ /dev/null @@ -1,1624 +0,0 @@ - - - - - - -Iterator Facade - - - - - - - -
-

Iterator Facade

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract: - - -iterator_facade is a base class template that implements the -interface of standard iterators in terms of a few core functions -and associated types, to be supplied by a derived iterator class.
- -
-

Overview

- - - - - -

While the iterator interface is rich, there is a core subset of the -interface that is necessary for all the functionality. We have -identified the following core behaviors for iterators:

-
    -
  • dereferencing
  • -
  • incrementing
  • -
  • decrementing
  • -
  • equality comparison
  • -
  • random-access motion
  • -
  • distance measurement
  • -
-

In addition to the behaviors listed above, the core interface elements -include the associated types exposed through iterator traits: -value_type, reference, difference_type, and -iterator_category.

-

Iterator facade uses the Curiously Recurring Template -Pattern (CRTP) [Cop95] so that the user can specify the behavior -of iterator_facade in a derived class. Former designs used -policy objects to specify the behavior, but that approach was -discarded for several reasons:

-
-
    -
  1. the creation and eventual copying of the policy object may create -overhead that can be avoided with the current approach.
  2. -
  3. The policy object approach does not allow for custom constructors -on the created iterator types, an essential feature if -iterator_facade should be used in other library -implementations.
  4. -
  5. Without the use of CRTP, the standard requirement that an -iterator's operator++ returns the iterator type itself -would mean that all iterators built with the library would -have to be specializations of iterator_facade<...>, rather -than something more descriptive like -indirect_iterator<T*>. Cumbersome type generator -metafunctions would be needed to build new parameterized -iterators, and a separate iterator_adaptor layer would be -impossible.
  6. -
-
-
-

Usage

-

The user of iterator_facade derives his iterator class from a -specialization of iterator_facade and passes the derived -iterator class as iterator_facade's first template parameter. -The order of the other template parameters have been carefully -chosen to take advantage of useful defaults. For example, when -defining a constant lvalue iterator, the user can pass a -const-qualified version of the iterator's value_type as -iterator_facade's Value parameter and omit the -Reference parameter which follows.

-

The derived iterator class must define member functions implementing -the iterator's core behaviors. The following table describes -expressions which are required to be valid depending on the category -of the derived iterator type. These member functions are described -briefly below and in more detail in the iterator facade -requirements.

-
- ---- - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionEffects
i.dereference()Access the value referred to
i.equal(j)Compare for equality with j
i.increment()Advance by one position
i.decrement()Retreat by one position
i.advance(n)Advance by n positions
i.distance_to(j)Measure the distance to j
-
- -

In addition to implementing the core interface functions, an iterator -derived from iterator_facade typically defines several -constructors. To model any of the standard iterator concepts, the -iterator must at least have a copy constructor. Also, if the iterator -type X is meant to be automatically interoperate with another -iterator type Y (as with constant and mutable iterators) then -there must be an implicit conversion from X to Y or from Y -to X (but not both), typically implemented as a conversion -constructor. Finally, if the iterator is to model Forward Traversal -Iterator or a more-refined iterator concept, a default constructor is -required.

-
-
-

Iterator Core Access

-

iterator_facade and the operator implementations need to be able -to access the core member functions in the derived class. Making the -core member functions public would expose an implementation detail to -the user. The design used here ensures that implementation details do -not appear in the public interface of the derived iterator type.

-

Preventing direct access to the core member functions has two -advantages. First, there is no possibility for the user to accidently -use a member function of the iterator when a member of the value_type -was intended. This has been an issue with smart pointer -implementations in the past. The second and main advantage is that -library implementers can freely exchange a hand-rolled iterator -implementation for one based on iterator_facade without fear of -breaking code that was accessing the public core member functions -directly.

-

In a naive implementation, keeping the derived class' core member -functions private would require it to grant friendship to -iterator_facade and each of the seven operators. In order to -reduce the burden of limiting access, iterator_core_access is -provided, a class that acts as a gateway to the core member functions -in the derived iterator class. The author of the derived class only -needs to grant friendship to iterator_core_access to make his core -member functions available to the library.

- - -

iterator_core_access will be typically implemented as an empty -class containing only private static member functions which invoke the -iterator core member functions. There is, however, no need to -standardize the gateway protocol. Note that even if -iterator_core_access used public member functions it would not -open a safety loophole, as every core member function preserves the -invariants of the iterator.

-
-
-

operator[]

-

The indexing operator for a generalized iterator presents special -challenges. A random access iterator's operator[] is only -required to return something convertible to its value_type. -Requiring that it return an lvalue would rule out currently-legal -random-access iterators which hold the referenced value in a data -member (e.g. counting_iterator), because *(p+n) is a reference -into the temporary iterator p+n, which is destroyed when -operator[] returns.

-

Writable iterators built with iterator_facade implement the -semantics required by the preferred resolution to issue 299 and -adopted by proposal n1550: the result of p[n] is an object -convertible to the iterator's value_type, and p[n] = x is -equivalent to *(p + n) = x (Note: This result object may be -implemented as a proxy containing a copy of p+n). This approach -will work properly for any random-access iterator regardless of the -other details of its implementation. A user who knows more about -the implementation of her iterator is free to implement an -operator[] that returns an lvalue in the derived iterator -class; it will hide the one supplied by iterator_facade from -clients of her iterator.

-
-
-

operator->

-

The reference type of a readable iterator (and today's input -iterator) need not in fact be a reference, so long as it is -convertible to the iterator's value_type. When the value_type -is a class, however, it must still be possible to access members -through operator->. Therefore, an iterator whose reference -type is not in fact a reference must return a proxy containing a copy -of the referenced value from its operator->.

-

The return types for iterator_facade's operator-> and -operator[] are not explicitly specified. Instead, those types -are described in terms of a set of requirements, which must be -satisfied by the iterator_facade implementation.

- - - - - -
[Cop95](1, 2) [Coplien, 1995] Coplien, J., Curiously Recurring Template -Patterns, C++ Report, February 1995, pp. 24-27.
-
-
-
-

Reference

- - - - - -
-template <
-    class Derived
-  , class Value
-  , class CategoryOrTraversal
-  , class Reference  = Value&
-  , class Difference = ptrdiff_t
->
-class iterator_facade {
- public:
-    typedef remove_const<Value>::type value_type;
-    typedef Reference reference;
-    typedef Value* pointer;
-    typedef Difference difference_type;
-    typedef /* see below */ iterator_category;
-
-    reference operator*() const;
-    /* see below */ operator->() const;
-    /* see below */ operator[](difference_type n) const;
-    Derived& operator++();
-    Derived operator++(int);
-    Derived& operator--();
-    Derived operator--(int);
-    Derived& operator+=(difference_type n);
-    Derived& operator-=(difference_type n);
-    Derived operator-(difference_type n) const;
- protected:
-    typedef iterator_facade iterator_facade_;
-};
-
-// Comparison operators
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator difference
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-/* see below */
-operator-(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-          iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator addition
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
-

The iterator_category member of iterator_facade is

-
-iterator-category(CategoryOrTraversal, value_type, reference)
-
-

where iterator-category is defined as follows:

-
-iterator-category(C,R,V) :=
-   if (C is convertible to std::input_iterator_tag
-       || C is convertible to std::output_iterator_tag
-   )
-       return C
-
-   else if (C is not convertible to incrementable_traversal_tag)
-       the program is ill-formed
-
-   else return a type X satisfying the following two constraints:
-
-      1. X is convertible to X1, and not to any more-derived
-         type, where X1 is defined by:
-
-           if (R is a reference type
-               && C is convertible to forward_traversal_tag)
-           {
-               if (C is convertible to random_access_traversal_tag)
-                   X1 = random_access_iterator_tag
-               else if (C is convertible to bidirectional_traversal_tag)
-                   X1 = bidirectional_iterator_tag
-               else
-                   X1 = forward_iterator_tag
-           }
-           else
-           {
-               if (C is convertible to single_pass_traversal_tag
-                   && R is convertible to V)
-                   X1 = input_iterator_tag
-               else
-                   X1 = C
-           }
-
-      2. category-to-traversal(X) is convertible to the most
-         derived traversal tag type to which X is also
-         convertible, and not to any more-derived traversal tag
-         type.
-
-

[Note: the intention is to allow iterator_category to be one of -the five original category tags when convertibility to one of the -traversal tags would add no information]

- - - -

The enable_if_interoperable template used above is for exposition -purposes. The member operators should only be in an overload set -provided the derived types Dr1 and Dr2 are interoperable, -meaning that at least one of the types is convertible to the other. The -enable_if_interoperable approach uses SFINAE to take the operators -out of the overload set when the types are not interoperable. -The operators should behave as-if enable_if_interoperable -were defined to be:

-
-template <bool, typename> enable_if_interoperable_impl
-{};
-
-template <typename T> enable_if_interoperable_impl<true,T>
-{ typedef T type; };
-
-template<typename Dr1, typename Dr2, typename T>
-struct enable_if_interoperable
-  : enable_if_interoperable_impl<
-        is_convertible<Dr1,Dr2>::value || is_convertible<Dr2,Dr1>::value
-      , T
-    >
-{};
-
-
-

iterator_facade Requirements

-

The following table describes the typical valid expressions on -iterator_facade's Derived parameter, depending on the -iterator concept(s) it will model. The operations in the first -column must be made accessible to member functions of class -iterator_core_access. In addition, -static_cast<Derived*>(iterator_facade*) shall be well-formed.

-

In the table below, F is iterator_facade<X,V,C,R,D>, a is an -object of type X, b and c are objects of type const X, -n is an object of F::difference_type, y is a constant -object of a single pass iterator type interoperable with X, and z -is a constant object of a random access traversal iterator type -interoperable with X.

-
-

iterator_facade Core Operations

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeAssertion/NoteUsed to implement Iterator -Concept(s)
c.dereference()F::reference Readable Iterator, Writable -Iterator
c.equal(y)convertible to booltrue iff c and y -refer to the same -position.Single Pass Iterator
a.increment()unused Incrementable Iterator
a.decrement()unused Bidirectional Traversal -Iterator
a.advance(n)unused Random Access Traversal -Iterator
c.distance_to(z)convertible to -F::difference_typeequivalent to -distance(c, X(z)).Random Access Traversal -Iterator
-
-
-
-

iterator_facade operations

-

The operations in this section are described in terms of operations on -the core interface of Derived which may be inaccessible -(i.e. private). The implementation should access these operations -through member functions of class iterator_core_access.

-

reference operator*() const;

- --- - - - -
Returns:static_cast<Derived const*>(this)->dereference()
-

operator->() const; (see below)

- --- - - - -
Returns:

If reference is a reference type, an object -of type pointer equal to:

-
-&static_cast<Derived const*>(this)->dereference()
-
-

Otherwise returns an object of unspecified type such that, -(*static_cast<Derived const*>(this))->m is equivalent to (w = **static_cast<Derived const*>(this), -w.m) for some temporary object w of type value_type.

-
-

unspecified operator[](difference_type n) const;

- --- - - - -
Returns:an object convertible to value_type. For constant -objects v of type value_type, and n of type -difference_type, (*this)[n] = v is equivalent to -*(*this + n) = v, and static_cast<value_type -const&>((*this)[n]) is equivalent to -static_cast<value_type const&>(*(*this + n))
-

Derived& operator++();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->increment();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator++(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-++*this;
-return tmp;
-
-
-

Derived& operator--();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->decrement();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator--(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
---*this;
-return tmp;
-
-
-

Derived& operator+=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(n);
-return *static_cast<Derived*>(this);
-
-
-

Derived& operator-=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(-n);
-return *static_cast<Derived*>(this);
-
-
-

Derived operator-(difference_type n) const;

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp -= n;
-
-
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp += n;
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).equal((Dr2 const&)rhs).

-
-
Otherwise,
-

((Dr2 const&)rhs).equal((Dr1 const&)lhs).

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

!((Dr1 const&)lhs).equal((Dr2 const&)rhs).

-
-
Otherwise,
-

!((Dr2 const&)rhs).equal((Dr1 const&)lhs).

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) < 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) > 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) <= 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) >= 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) > 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) < 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) >= 0.

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) <= 0.

-
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,difference>::type
-operator -(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - - - -
Return Type:

if is_convertible<Dr2,Dr1>::value

-
-
-
then
-

difference shall be -iterator_traits<Dr1>::difference_type.

-
-
Otherwise
-

difference shall be iterator_traits<Dr2>::difference_type

-
-
-
-
Returns:

if is_convertible<Dr2,Dr1>::value

-
-
then
-

-((Dr1 const&)lhs).distance_to((Dr2 const&)rhs).

-
-
Otherwise,
-

((Dr2 const&)rhs).distance_to((Dr1 const&)lhs).

-
-
-
-
-
-
-

Tutorial Example

- - - -

In this section we'll walk through the implementation of a few -iterators using iterator_facade, based around the simple -example of a linked list of polymorphic objects. This example was -inspired by a posting by Keith Macdonald on the Boost-Users -mailing list.

-
-

The Problem

-

Say we've written a polymorphic linked list node base class:

-
-# include <iostream>
-
-struct node_base
-{
-    node_base() : m_next(0) {}
-
-    // Each node manages all of its tail nodes
-    virtual ~node_base() { delete m_next; }
-
-    // Access the rest of the list
-    node_base* next() const { return m_next; }
-
-    // print to the stream
-    virtual void print(std::ostream& s) const = 0;
-
-    // double the value
-    virtual void double_me() = 0;
-
-    void append(node_base* p)
-    {
-        if (m_next)
-            m_next->append(p);
-        else
-            m_next = p;
-    }
-
- private:
-    node_base* m_next;
-};
-
-

Lists can hold objects of different types by linking together -specializations of the following template:

-
-template <class T>
-struct node : node_base
-{
-    node(T x)
-      : m_value(x)
-    {}
-
-    void print(std::ostream& s) const { s << this->m_value; }
-    void double_me() { m_value += m_value; }
-
- private:
-    T m_value;
-};
-
-

And we can print any node using the following streaming operator:

-
-inline std::ostream& operator<<(std::ostream& s, node_base const& n)
-{
-    n.print(s);
-    return s;
-}
-
-

Our first challenge is to build an appropriate iterator over these -lists.

-
-
-

A Basic Iterator Using iterator_facade

-

We will construct a node_iterator class using inheritance from -iterator_facade to implement most of the iterator's operations.

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<...>
-{
-   ...
-};
-
-
-

Template Arguments for iterator_facade

-

iterator_facade has several template parameters, so we must decide -what types to use for the arguments. The parameters are Derived, -Value, CategoryOrTraversal, Reference, and Difference.

-
-

Derived

-

Because iterator_facade is meant to be used with the CRTP -[Cop95] the first parameter is the iterator class name itself, -node_iterator.

-
-
-

Value

-

The Value parameter determines the node_iterator's -value_type. In this case, we are iterating over node_base -objects, so Value will be node_base.

-
-
-

CategoryOrTraversal

-

Now we have to determine which iterator traversal concept our -node_iterator is going to model. Singly-linked lists only have -forward links, so our iterator can't can't be a bidirectional -traversal iterator. Our iterator should be able to make multiple -passes over the same linked list (unlike, say, an -istream_iterator which consumes the stream it traverses), so it -must be a forward traversal iterator. Therefore, we'll pass -boost::forward_traversal_tag in this position [1].

- - - - - -
[1]iterator_facade also supports old-style category -tags, so we could have passed std::forward_iterator_tag here; -either way, the resulting iterator's iterator_category will -end up being std::forward_iterator_tag.
-
-
-

Reference

-

The Reference argument becomes the type returned by -node_iterator's dereference operation, and will also be the -same as std::iterator_traits<node_iterator>::reference. The -library's default for this parameter is Value&; since -node_base& is a good choice for the iterator's reference -type, we can omit this argument, or pass use_default.

-
-
-

Difference

-

The Difference argument determines how the distance between -two node_iterators will be measured and will also be the -same as std::iterator_traits<node_iterator>::difference_type. -The library's default for Difference is std::ptrdiff_t, an -appropriate type for measuring the distance between any two -addresses in memory, and one that works for almost any iterator, -so we can omit this argument, too.

-

The declaration of node_iterator will therefore look something -like:

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<
-        node_iterator
-      , node_base
-      , boost::forward_traversal_tag
-    >
-{
-   ...
-};
-
-
-
-
-

Constructors and Data Members

-

Next we need to decide how to represent the iterator's position. -This representation will take the form of data members, so we'll -also need to write constructors to initialize them. The -node_iterator's position is quite naturally represented using -a pointer to a node_base. We'll need a constructor to build an -iterator from a node_base*, and a default constructor to -satisfy the forward traversal iterator requirements [2]. -Our node_iterator then becomes:

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<
-        node_iterator
-      , node_base
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iterator()
-      : m_node(0)
-    {}
-
-    explicit node_iterator(node_base* p)
-      : m_node(p)
-    {}
-
- private:
-    ...
-    node_base* m_node;
-};
-
- - - - - -
[2]Technically, the C++ standard places almost no -requirements on a default-constructed iterator, so if we were -really concerned with efficiency, we could've written the -default constructor to leave m_node uninitialized.
-
-
-

Implementing the Core Operations

-

The last step is to implement the core operations required by -the concepts we want our iterator to model. Referring to the -table, we can see that the first three rows are applicable -because node_iterator needs to satisfy the requirements for -readable iterator, single pass iterator, and incrementable -iterator.

-

We therefore need to supply dereference, -equal, and increment members. We don't want these members -to become part of node_iterator's public interface, so we can -make them private and grant friendship to -boost::iterator_core_access, a "back-door" that -iterator_facade uses to get access to the core operations:

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<
-        node_iterator
-      , node_base
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iterator()
-      : m_node(0) {}
-
-    explicit node_iterator(node_base* p)
-      : m_node(p) {}
-
- private:
-    friend class boost::iterator_core_access;
-
-    void increment() { m_node = m_node->next(); }
-
-    bool equal(node_iterator const& other) const
-    {
-        return this->m_node == other.m_node;
-    }
-
-    node_base& dereference() const { return *m_node; }
-
-    node_base* m_node;
-};
-
-

Voilà; a complete and conforming readable, forward-traversal -iterator! For a working example of its use, see this program.

-
-
-
-

A constant node_iterator

- -

Now, our node_iterator gives clients access to both node's print(std::ostream&) const member function, but also its -mutating double_me() member. If we wanted to build a -constant node_iterator, we'd only have to make three -changes:

-
-class const_node_iterator
-  : public boost::iterator_facade<
-        const_node_iterator
-      , node_base const
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    const_node_iterator()
-      : m_node(0) {}
-
-    explicit const_node_iterator(node_base* p)
-      : m_node(p) {}
-
- private:
-    friend class boost::iterator_core_access;
-
-    void increment() { m_node = m_node->next(); }
-
-    bool equal(const_node_iterator const& other) const
-    {
-        return this->m_node == other.m_node;
-    }
-
-    node_base const& dereference() const { return *m_node; }
-
-    node_base const* m_node;
-};
-
- -

As a matter of fact, node_iterator and const_node_iterator -are so similar that it makes sense to factor the common code out -into a template as follows:

-
-template <class Value>
-class node_iter
-  : public boost::iterator_facade<
-        node_iter<Value>
-      , Value
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iter()
-      : m_node(0) {}
-
-    explicit node_iter(Value* p)
-      : m_node(p) {}
-
- private:
-    friend class boost::iterator_core_access;
-
-    bool equal(node_iter<Value> const& other) const
-    {
-        return this->m_node == other.m_node;
-    }
-
-    void increment()
-    { m_node = m_node->next(); }
-
-    Value& dereference() const
-    { return *m_node; }
-
-    Value* m_node;
-};
-typedef node_iter<node_base> node_iterator;
-typedef node_iter<node_base const> node_const_iterator;
-
-
-
-

Interoperability

-

Our const_node_iterator works perfectly well on its own, but -taken together with node_iterator it doesn't quite meet -expectations. For example, we'd like to be able to pass a -node_iterator where a node_const_iterator was expected, -just as you can with std::list<int>'s iterator and -const_iterator. Furthermore, given a node_iterator and a -node_const_iterator into the same list, we should be able to -compare them for equality.

-

This expected ability to use two different iterator types together -is known as interoperability. Achieving interoperability in -our case is as simple as templatizing the equal function and -adding a templatized converting constructor [3] [4]:

-
-template <class Value>
-class node_iter
-  : public boost::iterator_facade<
-        node_iter<Value>
-      , Value
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iter()
-      : m_node(0) {}
-
-    explicit node_iter(Value* p)
-      : m_node(p) {}
-
-    template <class OtherValue>
-    node_iter(node_iter<OtherValue> const& other)
-      : m_node(other.m_node) {}
-
- private:
-    friend class boost::iterator_core_access;
-    template <class> friend class node_iter;
-
-    template <class OtherValue>
-    bool equal(node_iter<OtherValue> const& other) const
-    {
-        return this->m_node == other.m_node;
-    }
-
-    void increment()
-    { m_node = m_node->next(); }
-
-    Value& dereference() const
-    { return *m_node; }
-
-    Value* m_node;
-};
-typedef impl::node_iterator<node_base> node_iterator;
-typedef impl::node_iterator<node_base const> node_const_iterator;
-
- - - - - -
[3]If you're using an older compiler and it can't handle -this example, see the example code for workarounds.
- - - - - -
[4]If node_iterator had been a random access -traversal iterator, we'd have had to templatize its -distance_to function as well.
-

You can see an example program which exercises our interoperable -iterators here.

-
-
-

Telling the Truth

-

Now node_iterator and node_const_iterator behave exactly as -you'd expect... almost. We can compare them and we can convert in -one direction: from node_iterator to node_const_iterator. -If we try to convert from node_const_iterator to -node_iterator, we'll get an error when the converting -constructor tries to initialize node_iterator's m_node, a -node* with a node const*. So what's the problem?

-

The problem is that -boost::is_convertible<node_const_iterator,node_iterator>::value -will be true, but it should be false. is_convertible -lies because it can only see as far as the declaration of -node_iter's converting constructor, but can't look inside at -the definition to make sure it will compile. A perfect solution -would make node_iter's converting constructor disappear when -the m_node conversion would fail.

-

In fact, that sort of magic is possible using -boost::enable_if. By rewriting the converting constructor as -follows, we can remove it from the overload set when it's not -appropriate:

-
-#include <boost/type_traits/is_convertible.hpp>
-#include <boost/utility/enable_if.hpp>
-
-  ...
-
-private:
-  struct enabler {};
-
-public:
-  template <class OtherValue>
-  node_iter(
-      node_iter<OtherValue> const& other
-    , typename boost::enable_if<
-          boost::is_convertible<OtherValue*,Value*>
-        , enabler
-      >::type = enabler()
-  )
-    : m_node(other.m_node) {}
-
-
-
-

Wrap Up

-

This concludes our iterator_facade tutorial, but before you -stop reading we urge you to take a look at iterator_adaptor. -There's another way to approach writing these iterators which might -even be superior.

-
-
-
- - diff --git a/doc/iterator_facade.pdf b/doc/iterator_facade.pdf deleted file mode 100755 index 30d46d2..0000000 Binary files a/doc/iterator_facade.pdf and /dev/null differ diff --git a/doc/iterator_facade.rst b/doc/iterator_facade.rst deleted file mode 100644 index 4cbafe6..0000000 --- a/doc/iterator_facade.rst +++ /dev/null @@ -1,44 +0,0 @@ -.. 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) - -++++++++++++++++ - Iterator Facade -++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: iterator_facade_abstract.rst - -.. contents:: Table of Contents - -Overview -======== - -.. include:: iterator_facade_body.rst - - -Reference -========= - -.. include:: iterator_facade_ref.rst - -.. _counting: counting_iterator.html - -Tutorial Example -================ - -.. include:: iterator_facade_tutorial.rst - diff --git a/doc/iterator_facade_abstract.rst b/doc/iterator_facade_abstract.rst deleted file mode 100644 index 519cda7..0000000 --- a/doc/iterator_facade_abstract.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. 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) - -``iterator_facade`` is a base class template that implements the -interface of standard iterators in terms of a few core functions -and associated types, to be supplied by a derived iterator class. - diff --git a/doc/iterator_facade_body.rst b/doc/iterator_facade_body.rst deleted file mode 100644 index 4b3059d..0000000 --- a/doc/iterator_facade_body.rst +++ /dev/null @@ -1,195 +0,0 @@ -.. 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) - -.. Version 1.1 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - - -While the iterator interface is rich, there is a core subset of the -interface that is necessary for all the functionality. We have -identified the following core behaviors for iterators: - -* dereferencing -* incrementing -* decrementing -* equality comparison -* random-access motion -* distance measurement - -In addition to the behaviors listed above, the core interface elements -include the associated types exposed through iterator traits: -``value_type``, ``reference``, ``difference_type``, and -``iterator_category``. - -Iterator facade uses the Curiously Recurring Template -Pattern (CRTP) [Cop95]_ so that the user can specify the behavior -of ``iterator_facade`` in a derived class. Former designs used -policy objects to specify the behavior, but that approach was -discarded for several reasons: - - 1. the creation and eventual copying of the policy object may create - overhead that can be avoided with the current approach. - - 2. The policy object approach does not allow for custom constructors - on the created iterator types, an essential feature if - ``iterator_facade`` should be used in other library - implementations. - - 3. Without the use of CRTP, the standard requirement that an - iterator's ``operator++`` returns the iterator type itself - would mean that all iterators built with the library would - have to be specializations of ``iterator_facade<...>``, rather - than something more descriptive like - ``indirect_iterator``. Cumbersome type generator - metafunctions would be needed to build new parameterized - iterators, and a separate ``iterator_adaptor`` layer would be - impossible. - -Usage ------ - -The user of ``iterator_facade`` derives his iterator class from a -specialization of ``iterator_facade`` and passes the derived -iterator class as ``iterator_facade``\ 's first template parameter. -The order of the other template parameters have been carefully -chosen to take advantage of useful defaults. For example, when -defining a constant lvalue iterator, the user can pass a -const-qualified version of the iterator's ``value_type`` as -``iterator_facade``\ 's ``Value`` parameter and omit the -``Reference`` parameter which follows. - -The derived iterator class must define member functions implementing -the iterator's core behaviors. The following table describes -expressions which are required to be valid depending on the category -of the derived iterator type. These member functions are described -briefly below and in more detail in the iterator facade -requirements. - - +------------------------+-------------------------------+ - |Expression |Effects | - +========================+===============================+ - |``i.dereference()`` |Access the value referred to | - +------------------------+-------------------------------+ - |``i.equal(j)`` |Compare for equality with ``j``| - +------------------------+-------------------------------+ - |``i.increment()`` |Advance by one position | - +------------------------+-------------------------------+ - |``i.decrement()`` |Retreat by one position | - +------------------------+-------------------------------+ - |``i.advance(n)`` |Advance by ``n`` positions | - +------------------------+-------------------------------+ - |``i.distance_to(j)`` |Measure the distance to ``j`` | - +------------------------+-------------------------------+ - -.. Should we add a comment that a zero overhead implementation of iterator_facade - is possible with proper inlining? - -In addition to implementing the core interface functions, an iterator -derived from ``iterator_facade`` typically defines several -constructors. To model any of the standard iterator concepts, the -iterator must at least have a copy constructor. Also, if the iterator -type ``X`` is meant to be automatically interoperate with another -iterator type ``Y`` (as with constant and mutable iterators) then -there must be an implicit conversion from ``X`` to ``Y`` or from ``Y`` -to ``X`` (but not both), typically implemented as a conversion -constructor. Finally, if the iterator is to model Forward Traversal -Iterator or a more-refined iterator concept, a default constructor is -required. - - - -Iterator Core Access --------------------- - -``iterator_facade`` and the operator implementations need to be able -to access the core member functions in the derived class. Making the -core member functions public would expose an implementation detail to -the user. The design used here ensures that implementation details do -not appear in the public interface of the derived iterator type. - -Preventing direct access to the core member functions has two -advantages. First, there is no possibility for the user to accidently -use a member function of the iterator when a member of the value_type -was intended. This has been an issue with smart pointer -implementations in the past. The second and main advantage is that -library implementers can freely exchange a hand-rolled iterator -implementation for one based on ``iterator_facade`` without fear of -breaking code that was accessing the public core member functions -directly. - -In a naive implementation, keeping the derived class' core member -functions private would require it to grant friendship to -``iterator_facade`` and each of the seven operators. In order to -reduce the burden of limiting access, ``iterator_core_access`` is -provided, a class that acts as a gateway to the core member functions -in the derived iterator class. The author of the derived class only -needs to grant friendship to ``iterator_core_access`` to make his core -member functions available to the library. - -.. This is no long uptodate -thw -.. Yes it is; I made sure of it! -DWA - -``iterator_core_access`` will be typically implemented as an empty -class containing only private static member functions which invoke the -iterator core member functions. There is, however, no need to -standardize the gateway protocol. Note that even if -``iterator_core_access`` used public member functions it would not -open a safety loophole, as every core member function preserves the -invariants of the iterator. - -``operator[]`` --------------- - -The indexing operator for a generalized iterator presents special -challenges. A random access iterator's ``operator[]`` is only -required to return something convertible to its ``value_type``. -Requiring that it return an lvalue would rule out currently-legal -random-access iterators which hold the referenced value in a data -member (e.g. |counting|_), because ``*(p+n)`` is a reference -into the temporary iterator ``p+n``, which is destroyed when -``operator[]`` returns. - -.. |counting| replace:: ``counting_iterator`` - -Writable iterators built with ``iterator_facade`` implement the -semantics required by the preferred resolution to `issue 299`_ and -adopted by proposal n1550_: the result of ``p[n]`` is an object -convertible to the iterator's ``value_type``, and ``p[n] = x`` is -equivalent to ``*(p + n) = x`` (Note: This result object may be -implemented as a proxy containing a copy of ``p+n``). This approach -will work properly for any random-access iterator regardless of the -other details of its implementation. A user who knows more about -the implementation of her iterator is free to implement an -``operator[]`` that returns an lvalue in the derived iterator -class; it will hide the one supplied by ``iterator_facade`` from -clients of her iterator. - -.. _n1550: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html - -.. _`issue 299`: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#299 - -.. _`operator arrow`: - - -``operator->`` --------------- - -The ``reference`` type of a readable iterator (and today's input -iterator) need not in fact be a reference, so long as it is -convertible to the iterator's ``value_type``. When the ``value_type`` -is a class, however, it must still be possible to access members -through ``operator->``. Therefore, an iterator whose ``reference`` -type is not in fact a reference must return a proxy containing a copy -of the referenced value from its ``operator->``. - -The return types for ``iterator_facade``\ 's ``operator->`` and -``operator[]`` are not explicitly specified. Instead, those types -are described in terms of a set of requirements, which must be -satisfied by the ``iterator_facade`` implementation. - -.. [Cop95] [Coplien, 1995] Coplien, J., Curiously Recurring Template - Patterns, C++ Report, February 1995, pp. 24-27. - diff --git a/doc/iterator_facade_ref.rst b/doc/iterator_facade_ref.rst deleted file mode 100644 index c1baf9b..0000000 --- a/doc/iterator_facade_ref.rst +++ /dev/null @@ -1,441 +0,0 @@ -.. 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) - -.. Version 1.3 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - - -.. parsed-literal:: - - template < - class Derived - , class Value - , class CategoryOrTraversal - , class Reference = Value& - , class Difference = ptrdiff_t - > - class iterator_facade { - public: - typedef remove_const::type value_type; - typedef Reference reference; - typedef Value\* pointer; - typedef Difference difference_type; - typedef /* see below__ \*/ iterator_category; - - reference operator\*() const; - /* see below__ \*/ operator->() const; - /* see below__ \*/ operator[](difference_type n) const; - Derived& operator++(); - Derived operator++(int); - Derived& operator--(); - Derived operator--(int); - Derived& operator+=(difference_type n); - Derived& operator-=(difference_type n); - Derived operator-(difference_type n) const; - protected: - typedef iterator_facade iterator_facade\_; - }; - - // Comparison operators - template - typename enable_if_interoperable::type // exposition - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator difference - template - /* see below__ \*/ - operator-(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator addition - template - Derived operator+ (iterator_facade const&, - typename Derived::difference_type n); - - template - Derived operator+ (typename Derived::difference_type n, - iterator_facade const&); - -__ `iterator category`_ - -__ `operator arrow`_ - -__ brackets_ - -__ minus_ - -.. _`iterator category`: - -The ``iterator_category`` member of ``iterator_facade`` is - -.. parsed-literal:: - - *iterator-category*\ (CategoryOrTraversal, value_type, reference) - -where *iterator-category* is defined as follows: - -.. include:: facade_iterator_category.rst - -The ``enable_if_interoperable`` template used above is for exposition -purposes. The member operators should only be in an overload set -provided the derived types ``Dr1`` and ``Dr2`` are interoperable, -meaning that at least one of the types is convertible to the other. The -``enable_if_interoperable`` approach uses SFINAE to take the operators -out of the overload set when the types are not interoperable. -The operators should behave *as-if* ``enable_if_interoperable`` -were defined to be:: - - template enable_if_interoperable_impl - {}; - - template enable_if_interoperable_impl - { typedef T type; }; - - template - struct enable_if_interoperable - : enable_if_interoperable_impl< - is_convertible::value || is_convertible::value - , T - > - {}; - - -``iterator_facade`` Requirements --------------------------------- - -The following table describes the typical valid expressions on -``iterator_facade``\ 's ``Derived`` parameter, depending on the -iterator concept(s) it will model. The operations in the first -column must be made accessible to member functions of class -``iterator_core_access``. In addition, -``static_cast(iterator_facade*)`` shall be well-formed. - -In the table below, ``F`` is ``iterator_facade``, ``a`` is an -object of type ``X``, ``b`` and ``c`` are objects of type ``const X``, -``n`` is an object of ``F::difference_type``, ``y`` is a constant -object of a single pass iterator type interoperable with ``X``, and ``z`` -is a constant object of a random access traversal iterator type -interoperable with ``X``. - -.. _`core operations`: - -.. topic:: ``iterator_facade`` Core Operations - - +--------------------+----------------------+-------------------------+---------------------------+ - |Expression |Return Type |Assertion/Note |Used to implement Iterator | - | | | |Concept(s) | - +====================+======================+=========================+===========================+ - |``c.dereference()`` |``F::reference`` | |Readable Iterator, Writable| - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``c.equal(y)`` |convertible to bool |true iff ``c`` and ``y`` |Single Pass Iterator | - | | |refer to the same | | - | | |position. | | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.increment()`` |unused | |Incrementable Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.decrement()`` |unused | |Bidirectional Traversal | - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.advance(n)`` |unused | |Random Access Traversal | - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``c.distance_to(z)``|convertible to |equivalent to |Random Access Traversal | - | |``F::difference_type``|``distance(c, X(z))``. |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - - - -``iterator_facade`` operations ------------------------------- - -The operations in this section are described in terms of operations on -the core interface of ``Derived`` which may be inaccessible -(i.e. private). The implementation should access these operations -through member functions of class ``iterator_core_access``. - -``reference operator*() const;`` - -:Returns: ``static_cast(this)->dereference()`` - -``operator->() const;`` (see below__) - -__ `operator arrow`_ - -:Returns: If ``reference`` is a reference type, an object - of type ``pointer`` equal to:: - - &static_cast(this)->dereference() - - Otherwise returns an object of unspecified type such that, - ``(*static_cast(this))->m`` is equivalent to ``(w = **static_cast(this), - w.m)`` for some temporary object ``w`` of type ``value_type``. - -.. _brackets: - -*unspecified* ``operator[](difference_type n) const;`` - -:Returns: an object convertible to ``value_type``. For constant - objects ``v`` of type ``value_type``, and ``n`` of type - ``difference_type``, ``(*this)[n] = v`` is equivalent to - ``*(*this + n) = v``, and ``static_cast((*this)[n])`` is equivalent to - ``static_cast(*(*this + n))`` - - - -``Derived& operator++();`` - -:Effects: - - :: - - static_cast(this)->increment(); - return *static_cast(this); - -``Derived operator++(int);`` - -:Effects: - - :: - - Derived tmp(static_cast(this)); - ++*this; - return tmp; - - -``Derived& operator--();`` - -:Effects: - - :: - - static_cast(this)->decrement(); - return *static_cast(this); - - -``Derived operator--(int);`` - -:Effects: - - :: - - Derived tmp(static_cast(this)); - --*this; - return tmp; - - -``Derived& operator+=(difference_type n);`` - -:Effects: - - :: - - static_cast(this)->advance(n); - return *static_cast(this); - - -``Derived& operator-=(difference_type n);`` - -:Effects: - - :: - - static_cast(this)->advance(-n); - return *static_cast(this); - - -``Derived operator-(difference_type n) const;`` - -:Effects: - - :: - - Derived tmp(static_cast(this)); - return tmp -= n; - -:: - - template - Derived operator+ (iterator_facade const&, - typename Derived::difference_type n); - - template - Derived operator+ (typename Derived::difference_type n, - iterator_facade const&); - -:Effects: - - :: - - Derived tmp(static_cast(this)); - return tmp += n; - - -:: - - template - typename enable_if_interoperable::type - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: - if ``is_convertible::value`` - - then - ``((Dr1 const&)lhs).equal((Dr2 const&)rhs)``. - - Otherwise, - ``((Dr2 const&)rhs).equal((Dr1 const&)lhs)``. - -:: - - template - typename enable_if_interoperable::type - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: - if ``is_convertible::value`` - - then - ``!((Dr1 const&)lhs).equal((Dr2 const&)rhs)``. - - Otherwise, - ``!((Dr2 const&)rhs).equal((Dr1 const&)lhs)``. - -:: - - template - typename enable_if_interoperable::type - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: - if ``is_convertible::value`` - - then - ``((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) < 0``. - - Otherwise, - ``((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) > 0``. - -:: - - template - typename enable_if_interoperable::type - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: - if ``is_convertible::value`` - - then - ``((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) <= 0``. - - Otherwise, - ``((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) >= 0``. - -:: - - template - typename enable_if_interoperable::type - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: - if ``is_convertible::value`` - - then - ``((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) > 0``. - - Otherwise, - ``((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) < 0``. - - -:: - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: - if ``is_convertible::value`` - - then - ``((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) >= 0``. - - Otherwise, - ``((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) <= 0``. - -.. _minus: - -:: - - template - typename enable_if_interoperable::type - operator -(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Return Type: - if ``is_convertible::value`` - - then - ``difference`` shall be - ``iterator_traits::difference_type``. - - Otherwise - ``difference`` shall be ``iterator_traits::difference_type`` - -:Returns: - if ``is_convertible::value`` - - then - ``-((Dr1 const&)lhs).distance_to((Dr2 const&)rhs)``. - - Otherwise, - ``((Dr2 const&)rhs).distance_to((Dr1 const&)lhs)``. diff --git a/doc/iterator_facade_tutorial.rst b/doc/iterator_facade_tutorial.rst deleted file mode 100755 index c133b48..0000000 --- a/doc/iterator_facade_tutorial.rst +++ /dev/null @@ -1,523 +0,0 @@ -.. Copyright David Abrahams 2004. Use, modification and distribution is -.. subject to 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) - -In this section we'll walk through the implementation of a few -iterators using ``iterator_facade``, based around the simple -example of a linked list of polymorphic objects. This example was -inspired by a `posting`__ by Keith Macdonald on the `Boost-Users`_ -mailing list. - -.. _`Boost-Users`: ../../../more/mailing_lists.htm#users - -__ http://thread.gmane.org/gmane.comp.lib.boost.user/5100 - -The Problem ------------ - -Say we've written a polymorphic linked list node base class:: - - # include - - struct node_base - { - node_base() : m_next(0) {} - - // Each node manages all of its tail nodes - virtual ~node_base() { delete m_next; } - - // Access the rest of the list - node_base* next() const { return m_next; } - - // print to the stream - virtual void print(std::ostream& s) const = 0; - - // double the value - virtual void double_me() = 0; - - void append(node_base* p) - { - if (m_next) - m_next->append(p); - else - m_next = p; - } - - private: - node_base* m_next; - }; - -Lists can hold objects of different types by linking together -specializations of the following template:: - - template - struct node : node_base - { - node(T x) - : m_value(x) - {} - - void print(std::ostream& s) const { s << this->m_value; } - void double_me() { m_value += m_value; } - - private: - T m_value; - }; - -And we can print any node using the following streaming operator:: - - inline std::ostream& operator<<(std::ostream& s, node_base const& n) - { - n.print(s); - return s; - } - -Our first challenge is to build an appropriate iterator over these -lists. - -A Basic Iterator Using ``iterator_facade`` ------------------------------------------- - -We will construct a ``node_iterator`` class using inheritance from -``iterator_facade`` to implement most of the iterator's operations. - -:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade<...> - { - ... - }; - - - -Template Arguments for ``iterator_facade`` -.......................................... - -``iterator_facade`` has several template parameters, so we must decide -what types to use for the arguments. The parameters are ``Derived``, -``Value``, ``CategoryOrTraversal``, ``Reference``, and ``Difference``. - - -``Derived`` -''''''''''' - -Because ``iterator_facade`` is meant to be used with the CRTP -[Cop95]_ the first parameter is the iterator class name itself, -``node_iterator``. - -``Value`` -''''''''' - -The ``Value`` parameter determines the ``node_iterator``\ 's -``value_type``. In this case, we are iterating over ``node_base`` -objects, so ``Value`` will be ``node_base``. - - -``CategoryOrTraversal`` -''''''''''''''''''''''' - -Now we have to determine which `iterator traversal concept`_ our -``node_iterator`` is going to model. Singly-linked lists only have -forward links, so our iterator can't can't be a `bidirectional -traversal iterator`_. Our iterator should be able to make multiple -passes over the same linked list (unlike, say, an -``istream_iterator`` which consumes the stream it traverses), so it -must be a `forward traversal iterator`_. Therefore, we'll pass -``boost::forward_traversal_tag`` in this position [#category]_. - -.. [#category] ``iterator_facade`` also supports old-style category - tags, so we could have passed ``std::forward_iterator_tag`` here; - either way, the resulting iterator's ``iterator_category`` will - end up being ``std::forward_iterator_tag``. - -``Reference`` -''''''''''''' - -The ``Reference`` argument becomes the type returned by -``node_iterator``\ 's dereference operation, and will also be the -same as ``std::iterator_traits::reference``. The -library's default for this parameter is ``Value&``; since -``node_base&`` is a good choice for the iterator's ``reference`` -type, we can omit this argument, or pass ``use_default``. - -``Difference`` -'''''''''''''' - -The ``Difference`` argument determines how the distance between -two ``node_iterator``\ s will be measured and will also be the -same as ``std::iterator_traits::difference_type``. -The library's default for ``Difference`` is ``std::ptrdiff_t``, an -appropriate type for measuring the distance between any two -addresses in memory, and one that works for almost any iterator, -so we can omit this argument, too. - -The declaration of ``node_iterator`` will therefore look something -like:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > - { - ... - }; - -Constructors and Data Members -............................. - -Next we need to decide how to represent the iterator's position. -This representation will take the form of data members, so we'll -also need to write constructors to initialize them. The -``node_iterator``\ 's position is quite naturally represented using -a pointer to a ``node_base``. We'll need a constructor to build an -iterator from a ``node_base*``, and a default constructor to -satisfy the `forward traversal iterator`_ requirements [#default]_. -Our ``node_iterator`` then becomes:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > - { - public: - node_iterator() - : m_node(0) - {} - - explicit node_iterator(node_base* p) - : m_node(p) - {} - - private: - ... - node_base* m_node; - }; - -.. [#default] Technically, the C++ standard places almost no - requirements on a default-constructed iterator, so if we were - really concerned with efficiency, we could've written the - default constructor to leave ``m_node`` uninitialized. - -Implementing the Core Operations -................................ - -The last step is to implement the `core operations`_ required by -the concepts we want our iterator to model. Referring to the -table__, we can see that the first three rows are applicable -because ``node_iterator`` needs to satisfy the requirements for -`readable iterator`_, `single pass iterator`_, and `incrementable -iterator`_. - -__ `core operations`_ - -We therefore need to supply ``dereference``, -``equal``, and ``increment`` members. We don't want these members -to become part of ``node_iterator``\ 's public interface, so we can -make them private and grant friendship to -``boost::iterator_core_access``, a "back-door" that -``iterator_facade`` uses to get access to the core operations:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > - { - public: - node_iterator() - : m_node(0) {} - - explicit node_iterator(node_base* p) - : m_node(p) {} - - private: - friend class boost::iterator_core_access; - - void increment() { m_node = m_node->next(); } - - bool equal(node_iterator const& other) const - { - return this->m_node == other.m_node; - } - - node_base& dereference() const { return *m_node; } - - node_base* m_node; - }; - -Voilà; a complete and conforming readable, forward-traversal -iterator! For a working example of its use, see `this program`__. - -__ ../example/node_iterator1.cpp - -A constant ``node_iterator`` ----------------------------- - -.. Sidebar:: Constant and Mutable iterators - - The term **mutable iterator** means an iterator through which - the object it references (its "referent") can be modified. A - **constant iterator** is one which doesn't allow modification of - its referent. - - The words *constant* and *mutable* don't refer to the ability to - modify the iterator itself. For example, an ``int const*`` is a - non-\ ``const`` *constant iterator*, which can be incremented - but doesn't allow modification of its referent, and ``int* - const`` is a ``const`` *mutable iterator*, which cannot be - modified but which allows modification of its referent. - - Confusing? We agree, but those are the standard terms. It - probably doesn't help much that a container's constant iterator - is called ``const_iterator``. - -Now, our ``node_iterator`` gives clients access to both ``node``\ -'s ``print(std::ostream&) const`` member function, but also its -mutating ``double_me()`` member. If we wanted to build a -*constant* ``node_iterator``, we'd only have to make three -changes: - -.. parsed-literal:: - - class const_node_iterator - : public boost::iterator_facade< - const_node_iterator - , node_base **const** - , boost::forward_traversal_tag - > - { - public: - const_node_iterator() - : m_node(0) {} - - explicit const_node_iterator(node_base* p) - : m_node(p) {} - - private: - friend class boost::iterator_core_access; - - void increment() { m_node = m_node->next(); } - - bool equal(const_node_iterator const& other) const - { - return this->m_node == other.m_node; - } - - node_base **const**\ & dereference() const { return \*m_node; } - - node_base **const**\ * m_node; - }; - -.. Sidebar:: ``const`` and an iterator's ``value_type`` - - The C++ standard requires an iterator's ``value_type`` *not* be - ``const``\ -qualified, so ``iterator_facade`` strips the - ``const`` from its ``Value`` parameter in order to produce the - iterator's ``value_type``. Making the ``Value`` argument - ``const`` provides a useful hint to ``iterator_facade`` that the - iterator is a *constant iterator*, and the default ``Reference`` - argument will be correct for all lvalue iterators. - -As a matter of fact, ``node_iterator`` and ``const_node_iterator`` -are so similar that it makes sense to factor the common code out -into a template as follows:: - - template - class node_iter - : public boost::iterator_facade< - node_iter - , Value - , boost::forward_traversal_tag - > - { - public: - node_iter() - : m_node(0) {} - - explicit node_iter(Value* p) - : m_node(p) {} - - private: - friend class boost::iterator_core_access; - - bool equal(node_iter const& other) const - { - return this->m_node == other.m_node; - } - - void increment() - { m_node = m_node->next(); } - - Value& dereference() const - { return *m_node; } - - Value* m_node; - }; - typedef node_iter node_iterator; - typedef node_iter node_const_iterator; - - -Interoperability ----------------- - -Our ``const_node_iterator`` works perfectly well on its own, but -taken together with ``node_iterator`` it doesn't quite meet -expectations. For example, we'd like to be able to pass a -``node_iterator`` where a ``node_const_iterator`` was expected, -just as you can with ``std::list``\ 's ``iterator`` and -``const_iterator``. Furthermore, given a ``node_iterator`` and a -``node_const_iterator`` into the same list, we should be able to -compare them for equality. - -This expected ability to use two different iterator types together -is known as |interoperability|_. Achieving interoperability in -our case is as simple as templatizing the ``equal`` function and -adding a templatized converting constructor [#broken]_ [#random]_:: - - template - class node_iter - : public boost::iterator_facade< - node_iter - , Value - , boost::forward_traversal_tag - > - { - public: - node_iter() - : m_node(0) {} - - explicit node_iter(Value* p) - : m_node(p) {} - - template - node_iter(node_iter const& other) - : m_node(other.m_node) {} - - private: - friend class boost::iterator_core_access; - template friend class node_iter; - - template - bool equal(node_iter const& other) const - { - return this->m_node == other.m_node; - } - - void increment() - { m_node = m_node->next(); } - - Value& dereference() const - { return *m_node; } - - Value* m_node; - }; - typedef impl::node_iterator node_iterator; - typedef impl::node_iterator node_const_iterator; - -.. |interoperability| replace:: **interoperability** -.. _interoperability: new-iter-concepts.html#interoperable-iterators-lib-interoperable-iterators - -.. [#broken] If you're using an older compiler and it can't handle - this example, see the `example code`__ for workarounds. - -.. [#random] If ``node_iterator`` had been a `random access - traversal iterator`_, we'd have had to templatize its - ``distance_to`` function as well. - - -__ ../example/node_iterator2.hpp - -You can see an example program which exercises our interoperable -iterators `here`__. - -__ ../example/node_iterator2.cpp - -Telling the Truth ------------------ - -Now ``node_iterator`` and ``node_const_iterator`` behave exactly as -you'd expect... almost. We can compare them and we can convert in -one direction: from ``node_iterator`` to ``node_const_iterator``. -If we try to convert from ``node_const_iterator`` to -``node_iterator``, we'll get an error when the converting -constructor tries to initialize ``node_iterator``\ 's ``m_node``, a -``node*`` with a ``node const*``. So what's the problem? - -The problem is that -``boost::``\ |is_convertible|_\ ``::value`` -will be ``true``, but it should be ``false``. |is_convertible|_ -lies because it can only see as far as the *declaration* of -``node_iter``\ 's converting constructor, but can't look inside at -the *definition* to make sure it will compile. A perfect solution -would make ``node_iter``\ 's converting constructor disappear when -the ``m_node`` conversion would fail. - -.. |is_convertible| replace:: ``is_convertible`` -.. _is_convertible: ../../type_traits/index.html#relationships - -In fact, that sort of magic is possible using -|enable_if|__. By rewriting the converting constructor as -follows, we can remove it from the overload set when it's not -appropriate:: - - #include - #include - - ... - - private: - struct enabler {}; - - public: - template - node_iter( - node_iter const& other - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() - ) - : m_node(other.m_node) {} - -.. |enable_if| replace:: ``boost::enable_if`` -__ ../../utility/enable_if.html - - -Wrap Up -------- - -This concludes our ``iterator_facade`` tutorial, but before you -stop reading we urge you to take a look at |iterator_adaptor|__. -There's another way to approach writing these iterators which might -even be superior. - -.. |iterator_adaptor| replace:: ``iterator_adaptor`` -__ iterator_adaptor.html - -.. _`iterator traversal concept`: new-iter-concepts.html#iterator-traversal-concepts-lib-iterator-traversal -.. _`readable iterator`: new-iter-concepts.html#readable-iterators-lib-readable-iterators -.. _`lvalue iterator`: new-iter-concepts.html#lvalue-iterators-lib-lvalue-iterators -.. _`single pass iterator`: new-iter-concepts.html#single-pass-iterators-lib-single-pass-iterators -.. _`incrementable iterator`: new-iter-concepts.html#incrementable-iterators-lib-incrementable-iterators -.. _`forward traversal iterator`: new-iter-concepts.html#forward-traversal-iterators-lib-forward-traversal-iterators -.. _`bidirectional traversal iterator`: new-iter-concepts.html#bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators -.. _`random access traversal iterator`: new-iter-concepts.html#random-access-traversal-iterators-lib-random-access-traversal-iterators - diff --git a/doc/iterator_traits.html b/doc/iterator_traits.html deleted file mode 100755 index 35c743b..0000000 --- a/doc/iterator_traits.html +++ /dev/null @@ -1,400 +0,0 @@ - - - - - - -Iterator Traits - - - - - - - -
-

Iterator Traits

- --- - - - - - - - - - - - -
Author:David Abrahams
Contact:dave@boost-consulting.com
Organization:Boost Consulting
Date:2004-11-01
Copyright:Copyright David Abrahams 2004.
- - - - --- - - - -
abstract:Header <boost/iterator/iterator_traits.hpp> provides -the ability to access an iterator's associated types using -MPL-compatible metafunctions.
-
-

Overview

-

std::iterator_traits provides access to five associated types -of any iterator: its value_type, reference, pointer, -iterator_category, and difference_type. Unfortunately, -such a "multi-valued" traits template can be difficult to use in a -metaprogramming context. <boost/iterator/iterator_traits.hpp> -provides access to these types using a standard metafunctions.

-
-
-

Summary

-

Header <boost/iterator/iterator_traits.hpp>:

-
-template <class Iterator>
-struct iterator_value
-{
-    typedef typename
-      std::iterator_traits<Iterator>::value_type
-    type;
-};
-
-template <class Iterator>
-struct iterator_reference
-{
-    typedef typename
-      std::iterator_traits<Iterator>::reference
-    type;
-};
-
-
-template <class Iterator>
-struct iterator_pointer
-{
-    typedef typename
-      std::iterator_traits<Iterator>::pointer
-    type;
-};
-
-template <class Iterator>
-struct iterator_difference
-{
-    typedef typename
-      detail::iterator_traits<Iterator>::difference_type
-    type;
-};
-
-template <class Iterator>
-struct iterator_category
-{
-    typedef typename
-      detail::iterator_traits<Iterator>::iterator_category
-    type;
-};
-
-
-
-

Broken Compiler Notes

-

Because of workarounds in Boost, you may find that these -metafunctions actually work better than the facilities provided by -your compiler's standard library.

-

On compilers that don't support partial specialization, such as -Microsoft Visual C++ 6.0 or 7.0, you may need to manually invoke -BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION on the -value_type of pointers that are passed to these metafunctions.

-

Because of bugs in the implementation of GCC-2.9x, the name of -iterator_category is changed to iterator_category_ on that -compiler. A macro, BOOST_ITERATOR_CATEGORY, that expands to -either iterator_category or iterator_category_, as -appropriate to the platform, is provided for portability.

-
-
- - diff --git a/doc/iterator_traits.pdf b/doc/iterator_traits.pdf deleted file mode 100755 index b5c765a..0000000 Binary files a/doc/iterator_traits.pdf and /dev/null differ diff --git a/doc/iterator_traits.rst b/doc/iterator_traits.rst deleted file mode 100755 index 2000d47..0000000 --- a/doc/iterator_traits.rst +++ /dev/null @@ -1,98 +0,0 @@ -.. 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) - -+++++++++++++++++ - Iterator Traits -+++++++++++++++++ - -:Author: David Abrahams -:Contact: dave@boost-consulting.com -:organization: `Boost Consulting`_ -:date: $Date$ -:copyright: Copyright David Abrahams 2004. - -.. _`Boost Consulting`: http://www.boost-consulting.com - -:abstract: Header ```` provides - the ability to access an iterator's associated types using - MPL-compatible metafunctions_. - -.. _metafunctions: ../../mpl/doc/index.html#metafunctions - -Overview -======== - -``std::iterator_traits`` provides access to five associated types -of any iterator: its ``value_type``, ``reference``, ``pointer``, -``iterator_category``, and ``difference_type``. Unfortunately, -such a "multi-valued" traits template can be difficult to use in a -metaprogramming context. ```` -provides access to these types using a standard metafunctions_. - -Summary -======= - -Header ````:: - - template - struct iterator_value - { - typedef typename - std::iterator_traits::value_type - type; - }; - - template - struct iterator_reference - { - typedef typename - std::iterator_traits::reference - type; - }; - - - template - struct iterator_pointer - { - typedef typename - std::iterator_traits::pointer - type; - }; - - template - struct iterator_difference - { - typedef typename - detail::iterator_traits::difference_type - type; - }; - - template - struct iterator_category - { - typedef typename - detail::iterator_traits::iterator_category - type; - }; - -Broken Compiler Notes -===================== - -Because of workarounds in Boost, you may find that these -metafunctions_ actually work better than the facilities provided by -your compiler's standard library. - -On compilers that don't support partial specialization, such as -Microsoft Visual C++ 6.0 or 7.0, you may need to manually invoke -BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION_ on the -``value_type`` of pointers that are passed to these metafunctions. - -Because of bugs in the implementation of GCC-2.9x, the name of -``iterator_category`` is changed to ``iterator_category_`` on that -compiler. A macro, ``BOOST_ITERATOR_CATEGORY``, that expands to -either ``iterator_category`` or ``iterator_category_``, as -appropriate to the platform, is provided for portability. - -.. _BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION: ../../type_traits/index.html#transformations - diff --git a/doc/make_counting_iterator.rst b/doc/make_counting_iterator.rst deleted file mode 100755 index 8477093..0000000 --- a/doc/make_counting_iterator.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. 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) - -:: - - template - counting_iterator make_counting_iterator(Incrementable x); - -:Returns: An instance of ``counting_iterator`` - with ``current`` constructed from ``x``. - diff --git a/doc/make_filter_iterator.rst b/doc/make_filter_iterator.rst deleted file mode 100755 index 4374b60..0000000 --- a/doc/make_filter_iterator.rst +++ /dev/null @@ -1,19 +0,0 @@ -.. 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) - -:: - - template - filter_iterator - make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator()); - -:Returns: filter_iterator(f, x, end) - -:: - - template - filter_iterator - make_filter_iterator(Iterator x, Iterator end = Iterator()); - -:Returns: filter_iterator(x, end) diff --git a/doc/make_reverse_iterator.rst b/doc/make_reverse_iterator.rst deleted file mode 100644 index dea1364..0000000 --- a/doc/make_reverse_iterator.rst +++ /dev/null @@ -1,13 +0,0 @@ -.. 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) - -:: - - template - reverse_iteratorn - make_reverse_iterator(BidirectionalIterator x); - -:Returns: An instance of ``reverse_iterator`` - with a ``current`` constructed from ``x``. - diff --git a/doc/make_transform_iterator.rst b/doc/make_transform_iterator.rst deleted file mode 100755 index 6ac566b..0000000 --- a/doc/make_transform_iterator.rst +++ /dev/null @@ -1,23 +0,0 @@ -.. 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) - -:: - - template - transform_iterator - make_transform_iterator(Iterator it, UnaryFunction fun); - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - initialized to ``f`` and ``m_iterator`` initialized to ``x``. - - - -:: - - template - transform_iterator - make_transform_iterator(Iterator it); - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - default constructed and ``m_iterator`` initialized to ``x``. diff --git a/doc/make_zip_iterator.rst b/doc/make_zip_iterator.rst deleted file mode 100755 index e74b895..0000000 --- a/doc/make_zip_iterator.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. 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) - -:: - - template - zip_iterator - make_zip_iterator(IteratorTuple t); - -:Returns: An instance of ``zip_iterator`` with ``m_iterator_tuple`` - initialized to ``t``. diff --git a/doc/new-iter-concepts.html b/doc/new-iter-concepts.html deleted file mode 100755 index 2013fba..0000000 --- a/doc/new-iter-concepts.html +++ /dev/null @@ -1,1303 +0,0 @@ - - - - - - -New Iterator Concepts - - - - - - - -
-

New Iterator Concepts

- --- - - - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
Organization:Boost Consulting, Indiana University Open Systems -Lab, Zephyr Associates, Inc.
Date:2006-04-30
Number:This is a revised version of n1550=03-0133, which was -accepted for Technical Report 1 by the C++ standard -committee's library working group. This proposal is a -revision of paper n1297, n1477, and n1531.
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt -2003.
- - - - - --- - - - -
Abstract:We propose a new system of iterator concepts that treat -access and positioning independently. This allows the -concepts to more closely match the requirements -of algorithms and provides better categorizations -of iterators that are used in practice.
- -
-

Motivation

-

The standard iterator categories and requirements are flawed because -they use a single hierarchy of concepts to address two orthogonal -issues: iterator traversal and value access. As a result, many -algorithms with requirements expressed in terms of the iterator -categories are too strict. Also, many real-world iterators can not be -accurately categorized. A proxy-based iterator with random-access -traversal, for example, may only legally have a category of "input -iterator", so generic algorithms are unable to take advantage of its -random-access capabilities. The current iterator concept hierarchy is -geared towards iterator traversal (hence the category names), while -requirements that address value access sneak in at various places. The -following table gives a summary of the current value access -requirements in the iterator categories.

- ---- - - - - - - - - - - - - - - - - - - -
Value Access Requirements in Existing Iterator Categories
Output Iterator*i = a
Input Iterator*i is convertible to T
Forward Iterator*i is T& (or const T& once issue 200 -is resolved)
Random Access Iteratori[n] is convertible to T (also i[n] = t -is required for mutable iterators once issue 299 -is resolved)
-

Because iterator traversal and value access are mixed together in a -single hierarchy, many useful iterators can not be appropriately -categorized. For example, vector<bool>::iterator is almost a -random access iterator, but the return type is not bool& (see -issue 96 and Herb Sutter's paper J16/99-0008 = WG21 -N1185). Therefore, the iterators of vector<bool> only meet the -requirements of input iterator and output iterator. This is so -nonintuitive that the C++ standard contradicts itself on this point. -In paragraph 23.2.4/1 it says that a vector is a sequence that -supports random access iterators.

-

Another difficult-to-categorize iterator is the transform iterator, an -adaptor which applies a unary function object to the dereferenced -value of the some underlying iterator (see transform_iterator). -For unary functions such as times, the return type of -operator* clearly needs to be the result_type of the function -object, which is typically not a reference. Because random access -iterators are required to return lvalues from operator*, if you -wrap int* with a transform iterator, you do not get a random -access iterator as might be expected, but an input iterator.

-

A third example is found in the vertex and edge iterators of the -Boost Graph Library. These iterators return vertex and edge -descriptors, which are lightweight handles created on-the-fly. They -must be returned by-value. As a result, their current standard -iterator category is input_iterator_tag, which means that, -strictly speaking, you could not use these iterators with algorithms -like min_element(). As a temporary solution, the concept -Multi-Pass Input Iterator was introduced to describe the vertex and -edge descriptors, but as the design notes for the concept suggest, a -better solution is needed.

-

In short, there are many useful iterators that do not fit into the -current standard iterator categories. As a result, the following bad -things happen:

-
    -
  • Iterators are often mis-categorized.
  • -
  • Algorithm requirements are more strict than necessary, because they -cannot separate the need for random access or bidirectional -traversal from the need for a true reference return type.
  • -
-
-
-

Impact on the Standard

-

This proposal for TR1 is a pure extension. Further, the new iterator -concepts are backward-compatible with the old iterator requirements, -and old iterators are forward-compatible with the new iterator -concepts. That is to say, iterators that satisfy the old requirements -also satisfy appropriate concepts in the new system, and iterators -modeling the new concepts will automatically satisfy the appropriate -old requirements.

- - -
-

Possible (but not proposed) Changes to the Working Paper

-

The extensions in this paper suggest several changes we might make -to the working paper for the next standard. These changes are not -a formal part of this proposal for TR1.

-
-

Changes to Algorithm Requirements

-

The algorithms in the standard library could benefit from the new -iterator concepts because the new concepts provide a more accurate way -to express their type requirements. The result is algorithms that are -usable in more situations and have fewer type requirements.

-

For the next working paper (but not for TR1), the committee should -consider the following changes to the type requirements of algorithms. -These changes are phrased as textual substitutions, listing the -algorithms to which each textual substitution applies.

-

Forward Iterator -> Forward Traversal Iterator and Readable Iterator

-
-find_end, adjacent_find, search, search_n, rotate_copy, -lower_bound, upper_bound, equal_range, binary_search, -min_element, max_element
-

Forward Iterator (1) -> Single Pass Iterator and Readable Iterator, -Forward Iterator (2) -> Forward Traversal Iterator and Readable Iterator

-
-find_first_of
-

Forward Iterator -> Readable Iterator and Writable Iterator

-
-iter_swap
-

Forward Iterator -> Single Pass Iterator and Writable Iterator

-
-fill, generate
-

Forward Iterator -> Forward Traversal Iterator and Swappable Iterator

-
-rotate
-

Forward Iterator (1) -> Swappable Iterator and Single Pass Iterator, -Forward Iterator (2) -> Swappable Iterator and Incrementable Iterator

-
-swap_ranges
-
-
Forward Iterator -> Forward Traversal Iterator and Readable Iterator and Writable Iterator
-
remove, remove_if, unique
-
-

Forward Iterator -> Single Pass Iterator and Readable Iterator and Writable Iterator

-
-replace, replace_if
-
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator
-
reverse
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable and Swappable Iterator
-
partition
-
-

Bidirectional Iterator (1) -> Bidirectional Traversal Iterator and Readable Iterator, -Bidirectional Iterator (2) -> Bidirectional Traversal Iterator and Writable Iterator

-
-copy_backwards
-
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator and Readable Iterator
-
next_permutation, prev_permutation
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator and Writable Iterator
-
stable_partition, inplace_merge
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator
-
reverse_copy
-
Random Access Iterator -> Random Access Traversal Iterator and Readable and Writable Iterator
-
random_shuffle, sort, stable_sort, partial_sort, nth_element, push_heap, pop_heap -make_heap, sort_heap
-
Input Iterator (2) -> Incrementable Iterator and Readable Iterator
-
equal, mismatch
-
Input Iterator (2) -> Incrementable Iterator and Readable Iterator
-
transform
-
-
-
-

Deprecations

-

For the next working paper (but not for TR1), the committee should -consider deprecating the old iterator tags, and -std::iterator_traits, since it will be superceded by individual -traits metafunctions.

-
-
-

vector<bool>

-

For the next working paper (but not for TR1), the committee should -consider reclassifying vector<bool>::iterator as a Random -Access Traversal Iterator and Readable Iterator and Writable -Iterator.

-
-
-
-
-

Design

-

The iterator requirements are to be separated into two groups. One set -of concepts handles the syntax and semantics of value access:

-
    -
  • Readable Iterator
  • -
  • Writable Iterator
  • -
  • Swappable Iterator
  • -
  • Lvalue Iterator
  • -
-

The access concepts describe requirements related to operator* and -operator->, including the value_type, reference, and -pointer associated types.

-

The other set of concepts handles traversal:

-
    -
  • Incrementable Iterator
  • -
  • Single Pass Iterator
  • -
  • Forward Traversal Iterator
  • -
  • Bidirectional Traversal Iterator
  • -
  • Random Access Traversal Iterator
  • -
-

The refinement relationships for the traversal concepts are in the -following diagram.

-
traversal.png
-

In addition to the iterator movement operators, such as -operator++, the traversal concepts also include requirements on -position comparison such as operator== and operator<. The -reason for the fine grain slicing of the concepts into the -Incrementable and Single Pass is to provide concepts that are exact -matches with the original input and output iterator requirements.

-

This proposal also includes a concept for specifying when an iterator -is interoperable with another iterator, in the sense that int* is -interoperable with int const*.

-
    -
  • Interoperable Iterators
  • -
-

The relationship between the new iterator concepts and the old are -given in the following diagram.

-
oldeqnew.png
-

Like the old iterator requirements, we provide tags for purposes of -dispatching based on the traversal concepts. The tags are related via -inheritance so that a tag is convertible to another tag if the concept -associated with the first tag is a refinement of the second tag.

-

Our design reuses iterator_traits<Iter>::iterator_category to -indicate an iterator's traversal capability. To specify -capabilities not captured by any old-style iterator category, an -iterator designer can use an iterator_category type that is -convertible to both the the most-derived old iterator category tag -which fits, and the appropriate new iterator traversal tag.

- -

We do not provide tags for the purposes of dispatching based on the -access concepts, in part because we could not find a way to -automatically infer the right access tags for old-style iterators. -An iterator's writability may be dependent on the assignability of -its value_type and there's no known way to detect whether an -arbitrary type is assignable. Fortunately, the need for -dispatching based on access capability is not as great as the need -for dispatching based on traversal capability.

-

A difficult design decision concerned the operator[]. The direct -approach for specifying operator[] would have a return type of -reference; the same as operator*. However, going in this -direction would mean that an iterator satisfying the old Random Access -Iterator requirements would not necessarily be a model of Readable or -Writable Lvalue Iterator. Instead we have chosen a design that -matches the preferred resolution of issue 299: operator[] is -only 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 constant -object of type X, R is -std::iterator_traits<X>::reference, T is -std::iterator_traits<X>::value_type, and v is a constant -object of type T.

-
-

Readable Iterators [lib.readable.iterators]

-

A class or built-in type X models the Readable Iterator concept -for value type T if, in addition to X being Assignable and -Copy Constructible, the following expressions are valid and respect -the stated semantics. U is the type of any specified member of -type T.

- ----- - - - - - - - - - - - - - - - - - - - - - - -
Readable Iterator Requirements (in addition to Assignable and Copy Constructible)
ExpressionReturn TypeNote/Precondition
iterator_traits<X>::value_typeTAny non-reference, -non-cv-qualified type
*aConvertible to T
-
pre: a is dereferenceable. If a == b then *a
-
is equivalent to *b.
-
-
a->mU&pre: pre: (*a).m is well-defined. Equivalent to (*a).m.
- -
-
-

Writable Iterators [lib.writable.iterators]

-

A class or built-in type X models the Writable Iterator concept -if, in addition to X being Copy Constructible, the following -expressions are valid and respect the stated semantics. Writable -Iterators have an associated set of value types.

- ----- - - - - - - - - - - - - - - -
Writable Iterator Requirements (in addition to Copy Constructible)
ExpressionReturn TypePrecondition
*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 concept -if, in addition to X being Copy Constructible, the following -expressions are valid and respect the stated semantics.

- ----- - - - - - - - - - - - - - - -
Swappable Iterator Requirements (in addition to Copy Constructible)
ExpressionReturn TypePostcondition
iter_swap(a, b)voidthe 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 Swappable -Iterator. --end note]

-
-
-

Lvalue Iterators [lib.lvalue.iterators]

-

The Lvalue Iterator concept adds the requirement that the return -type of operator* type be a reference to the value type of the -iterator.

- ----- - - - - - - - - - - - - - - -
Lvalue Iterator Requirements
ExpressionReturn TypeNote/Assertion
*aT&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 Readable -Iterator 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 are -constant objects of type X, r and s are mutable objects of -type 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 Copy -Constructible, the following expressions are valid and respect the -stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible)
ExpressionReturn TypeAssertion
++rX&&r == &++r
r++  
*r++  
iterator_traversal<X>::typeConvertible to -incrementable_traversal_tag 
-

If X is a Writable Iterator then X a(r++); is equivalent -to X a(r); ++r; and *r++ = o is equivalent -to *r = o; ++r. -If X is a Readable Iterator then T z(*r++); is equivalent -to T z(*r); ++r;.

- -
-
-

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 stated -semantics.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Single Pass Iterator Requirements (in addition to Incrementable Iterator and Equality -Comparable)
ExpressionReturn TypeOperational -SemanticsAssertion/ -Pre-/Post-condition
++rX& pre: r is -dereferenceable; post: -r is dereferenceable or -r is past-the-end
a == bconvertible to bool == is an equivalence -relation over its domain
a != bconvertible to bool!(a == b) 
iterator_traversal<X>::typeConvertible to -single_pass_traversal_tag  
- -
-
-

Forward 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 Default -Constructible and Single Pass Iterator, the following expressions are -valid and respect the stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Forward Traversal Iterator Requirements (in addition to Default Constructible and Single Pass Iterator)
ExpressionReturn TypeAssertion/Note
X u;X&note: u may have a -singular value.
++rX&r == s and r is -dereferenceable implies -++r == ++s.
iterator_traits<X>::difference_typeA signed integral type representing -the distance between iterators 
iterator_traversal<X>::typeConvertible to -forward_traversal_tag 
- -
-
-

Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators]

-

A class or built-in type X models the Bidirectional Traversal -Iterator concept if, in addition to X meeting the requirements of -Forward Traversal Iterator, the following expressions are valid and -respect the stated semantics.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - -
Bidirectional Traversal Iterator Requirements (in addition to Forward Traversal -Iterator)
ExpressionReturn TypeOperational -SemanticsAssertion/ -Pre-/Post-condition
--rX& 

pre: there exists -s such that r -== ++s. post: -s is -dereferenceable.

-

++(--r) == r. ---r == --s -implies r == -s. &r == &--r.

-
r--convertible to const X&
-{
-  X tmp = r;
-  --r;
-  return tmp;
-}
-
-
 
iterator_traversal<X>::typeConvertible to -bidirectional_traversal_tag  
- -
-
-

Random Access Traversal Iterators [lib.random.access.traversal.iterators]

-

A class or built-in type X models the Random Access Traversal -Iterator concept if the following expressions are valid and respect -the stated semantics. In the table below, Distance is -iterator_traits<X>::difference_type and n represents a -constant object of type Distance.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal Iterator)
ExpressionReturn TypeOperational SemanticsAssertion/ -Precondition
r += nX&
-{
-  Distance m = n;
-  if (m >= 0)
-    while (m--)
-      ++r;
-  else
-    while (m++)
-      --r;
-  return r;
-}
-
-
 
a + n, n + aX{ X tmp = a; return tmp -+= n; } 
r -= nX&return r += -n 
a - nX{ X tmp = a; return tmp --= n; } 
b - aDistancea < b ?  distance(a,b) -: -distance(b,a)pre: there exists 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] = vconvertible to T*(a + n) = vpre: a is a Writable -Iterator
a < bconvertible to boolb - a > 0< is a total -ordering relation
a > bconvertible to boolb < a> is a total -ordering relation
a >= bconvertible to bool!(a < b) 
a <= bconvertible to bool!(a > b) 
iterator_traversal<X>::typeConvertible to -random_access_traversal_tag  
- -
-
-

Interoperable Iterators [lib.interoperable.iterators]

-

A class or built-in type X that models Single Pass Iterator is -interoperable with a class or built-in type Y that also models -Single Pass Iterator if the following expressions are valid and -respect the stated semantics. In the tables below, x is an object -of type X, y is an object of type Y, Distance is -iterator_traits<Y>::difference_type, and n represents a -constant object of type Distance.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeAssertion/Precondition/Postcondition
y = xYpost: y == x
Y(x)Ypost: Y(x) == x
x == yconvertible to bool== is an equivalence relation over its domain.
y == xconvertible to bool== is an equivalence relation over its domain.
x != yconvertible to boolbool(a==b) != bool(a!=b) over its domain.
y != xconvertible to boolbool(a==b) != bool(a!=b) over its domain.
-

If X and Y both model Random Access Traversal Iterator then -the following additional requirements must be met.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeOperational SemanticsAssertion/ Precondition
x < yconvertible to booly - x > 0< is a total ordering relation
y < xconvertible to boolx - y > 0< is a total ordering relation
x > yconvertible to booly < x> is a total ordering relation
y > xconvertible to boolx < y> is a total ordering relation
x >= yconvertible to bool!(x < y) 
y >= xconvertible to bool!(y < x) 
x <= yconvertible to bool!(x > y) 
y <= xconvertible to bool!(y > x) 
y - xDistancedistance(Y(x),y)pre: there exists a value n of -Distance such that x + n == y. -y == x + (y - x).
x - yDistancedistance(y,Y(x))pre: there exists a value n of -Distance such that y + n == x. -x == y + (x - y).
-
-
-
-
-

Addition to [lib.iterator.synopsis]

-
-// lib.iterator.traits, traits and tags
-template <class Iterator> struct is_readable_iterator;
-template <class Iterator> struct iterator_traversal;
-
-struct incrementable_traversal_tag { };
-struct single_pass_traversal_tag : incrementable_traversal_tag { };
-struct forward_traversal_tag : single_pass_traversal_tag { };
-struct bidirectional_traversal_tag : forward_traversal_tag { };
-struct random_access_traversal_tag : bidirectional_traversal_tag { };
-
-
-
-

Addition to [lib.iterator.traits]

-

The is_readable_iterator class -template satisfies the UnaryTypeTrait requirements.

-

Given an iterator type X, is_readable_iterator<X>::value -yields true if, for an object a of type X, *a is -convertible to iterator_traits<X>::value_type, and false -otherwise.

-

iterator_traversal<X>::type is

-
-category-to-traversal(iterator_traits<X>::iterator_category) 
-
-

where category-to-traversal is defined as follows

-
-category-to-traversal(C) =
-    if (C is convertible to incrementable_traversal_tag)
-        return C;
-    else if (C is convertible to random_access_iterator_tag)
-        return random_access_traversal_tag;
-    else if (C is convertible to bidirectional_iterator_tag)
-        return bidirectional_traversal_tag;
-    else if (C is convertible to forward_iterator_tag)
-        return forward_traversal_tag;
-    else if (C is convertible to input_iterator_tag)
-        return single_pass_traversal_tag;
-    else if (C is convertible to output_iterator_tag)
-        return incrementable_traversal_tag;
-    else
-        the program is ill-formed
-
-
-
-
-

Footnotes

-

The UnaryTypeTrait concept is defined in n1519; the LWG is -considering adding the requirement that specializations are derived -from their nested ::type.

- -
-
- - diff --git a/doc/new-iter-concepts.pdf b/doc/new-iter-concepts.pdf deleted file mode 100755 index aa680ec..0000000 Binary files a/doc/new-iter-concepts.pdf and /dev/null differ diff --git a/doc/new-iter-concepts.rst b/doc/new-iter-concepts.rst deleted file mode 100644 index 4648183..0000000 --- a/doc/new-iter-concepts.rst +++ /dev/null @@ -1,803 +0,0 @@ -.. 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) - -++++++++++++++++++++++ - New Iterator Concepts -++++++++++++++++++++++ - -.. Version 1.25 of this ReStructuredText document is the same as - n1550_, the paper accepted by the LWG. - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ - -:Number: This is a revised version of n1550_\ =03-0133, which was - accepted for Technical Report 1 by the C++ standard - committee's library working group. This proposal is a - revision of paper n1297_, n1477_, and n1531_. - -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt - 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -.. _`Institute for Transport Railway Operation and Construction`: - http://www.ive.uni-hannover.de - -:Abstract: We propose a new system of iterator concepts that treat - access and positioning independently. This allows the - concepts to more closely match the requirements - of algorithms and provides better categorizations - of iterators that are used in practice. - -.. contents:: Table of Contents - -.. _n1297: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2001/n1297.html -.. _n1477: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1477.html -.. _n1531: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1531.html -.. _n1550: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1550.html - -============ - Motivation -============ - -The standard iterator categories and requirements are flawed because -they use a single hierarchy of concepts to address two orthogonal -issues: *iterator traversal* and *value access*. As a result, many -algorithms with requirements expressed in terms of the iterator -categories are too strict. Also, many real-world iterators can not be -accurately categorized. A proxy-based iterator with random-access -traversal, for example, may only legally have a category of "input -iterator", so generic algorithms are unable to take advantage of its -random-access capabilities. The current iterator concept hierarchy is -geared towards iterator traversal (hence the category names), while -requirements that address value access sneak in at various places. The -following table gives a summary of the current value access -requirements in the iterator categories. - -+------------------------------------------------------------------------------+ -|Value Access Requirements in Existing Iterator Categories | -+========================+=====================================================+ -|Output Iterator |``*i = a`` | -+------------------------+-----------------------------------------------------+ -|Input Iterator |``*i`` is convertible to ``T`` | -+------------------------+-----------------------------------------------------+ -|Forward Iterator |``*i`` is ``T&`` (or ``const T&`` once `issue 200`_ | -| |is resolved) | -+------------------------+-----------------------------------------------------+ -|Random Access Iterator |``i[n]`` is convertible to ``T`` (also ``i[n] = t`` | -| |is required for mutable iterators once `issue 299`_ | -| |is resolved) | -+------------------------+-----------------------------------------------------+ - -.. _issue 200: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#200 -.. _issue 299: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#299 - - -Because iterator traversal and value access are mixed together in a -single hierarchy, many useful iterators can not be appropriately -categorized. For example, ``vector::iterator`` is almost a -random access iterator, but the return type is not ``bool&`` (see -`issue 96`_ and Herb Sutter's paper J16/99-0008 = WG21 -N1185). Therefore, the iterators of ``vector`` only meet the -requirements of input iterator and output iterator. This is so -nonintuitive that the C++ standard contradicts itself on this point. -In paragraph 23.2.4/1 it says that a ``vector`` is a sequence that -supports random access iterators. - -.. _issue 96: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#96 - -Another difficult-to-categorize iterator is the transform iterator, an -adaptor which applies a unary function object to the dereferenced -value of the some underlying iterator (see `transform_iterator`_). -For unary functions such as ``times``, the return type of -``operator*`` clearly needs to be the ``result_type`` of the function -object, which is typically not a reference. Because random access -iterators are required to return lvalues from ``operator*``, if you -wrap ``int*`` with a transform iterator, you do not get a random -access iterator as might be expected, but an input iterator. - -.. _`transform_iterator`: http://www.boost.org/libs/utility/transform_iterator.htm - -A third example is found in the vertex and edge iterators of the -`Boost Graph Library`_. These iterators return vertex and edge -descriptors, which are lightweight handles created on-the-fly. They -must be returned by-value. As a result, their current standard -iterator category is ``input_iterator_tag``, which means that, -strictly speaking, you could not use these iterators with algorithms -like ``min_element()``. As a temporary solution, the concept -`Multi-Pass Input Iterator`_ was introduced to describe the vertex and -edge descriptors, but as the design notes for the concept suggest, a -better solution is needed. - -.. _Boost Graph Library: http://www.boost.org/libs/graph/doc/table_of_contents.html -.. _Multi-Pass Input Iterator: http://www.boost.org/libs/utility/MultiPassInputIterator.html - -In short, there are many useful iterators that do not fit into the -current standard iterator categories. As a result, the following bad -things happen: - -- Iterators are often mis-categorized. - -- Algorithm requirements are more strict than necessary, because they - cannot separate the need for random access or bidirectional - traversal from the need for a true reference return type. - - -======================== - Impact on the Standard -======================== - -This proposal for TR1 is a pure extension. Further, the new iterator -concepts are backward-compatible with the old iterator requirements, -and old iterators are forward-compatible with the new iterator -concepts. That is to say, iterators that satisfy the old requirements -also satisfy appropriate concepts in the new system, and iterators -modeling the new concepts will automatically satisfy the appropriate -old requirements. - -.. I think we need to say something about the resolution to allow - convertibility to any of the old-style tags as a TR issue (hope it - made it). -DWA - -.. Hmm, not sure I understand. Are you talking about whether a - standards conforming input iterator is allowed to have - a tag that is not input_iterator_tag but that - is convertible to input_iterator_tag? -JGS - -Possible (but not proposed) Changes to the Working Paper -======================================================== - -The extensions in this paper suggest several changes we might make -to the working paper for the next standard. These changes are not -a formal part of this proposal for TR1. - -Changes to Algorithm Requirements -+++++++++++++++++++++++++++++++++ - -The algorithms in the standard library could benefit from the new -iterator concepts because the new concepts provide a more accurate way -to express their type requirements. The result is algorithms that are -usable in more situations and have fewer type requirements. - -For the next working paper (but not for TR1), the committee should -consider the following changes to the type requirements of algorithms. -These changes are phrased as textual substitutions, listing the -algorithms to which each textual substitution applies. - -Forward Iterator -> Forward Traversal Iterator and Readable Iterator - - ``find_end, adjacent_find, search, search_n, rotate_copy, - lower_bound, upper_bound, equal_range, binary_search, - min_element, max_element`` - -Forward Iterator (1) -> Single Pass Iterator and Readable Iterator, -Forward Iterator (2) -> Forward Traversal Iterator and Readable Iterator - - ``find_first_of`` - -Forward Iterator -> Readable Iterator and Writable Iterator - - ``iter_swap`` - -Forward Iterator -> Single Pass Iterator and Writable Iterator - - ``fill, generate`` - -Forward Iterator -> Forward Traversal Iterator and Swappable Iterator - - ``rotate`` - -Forward Iterator (1) -> Swappable Iterator and Single Pass Iterator, -Forward Iterator (2) -> Swappable Iterator and Incrementable Iterator - - ``swap_ranges`` - -Forward Iterator -> Forward Traversal Iterator and Readable Iterator and Writable Iterator - ``remove, remove_if, unique`` - -Forward Iterator -> Single Pass Iterator and Readable Iterator and Writable Iterator - - ``replace, replace_if`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator - ``reverse`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable and Swappable Iterator - ``partition`` - -Bidirectional Iterator (1) -> Bidirectional Traversal Iterator and Readable Iterator, -Bidirectional Iterator (2) -> Bidirectional Traversal Iterator and Writable Iterator - - ``copy_backwards`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator and Readable Iterator - ``next_permutation, prev_permutation`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator and Writable Iterator - ``stable_partition, inplace_merge`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator - ``reverse_copy`` - -Random Access Iterator -> Random Access Traversal Iterator and Readable and Writable Iterator - ``random_shuffle, sort, stable_sort, partial_sort, nth_element, push_heap, pop_heap - make_heap, sort_heap`` - -Input Iterator (2) -> Incrementable Iterator and Readable Iterator - ``equal, mismatch`` - -Input Iterator (2) -> Incrementable Iterator and Readable Iterator - ``transform`` - -Deprecations -++++++++++++ - -For the next working paper (but not for TR1), the committee should -consider deprecating the old iterator tags, and -std::iterator_traits, since it will be superceded by individual -traits metafunctions. - -``vector`` -++++++++++++++++ - -For the next working paper (but not for TR1), the committee should -consider reclassifying ``vector::iterator`` as a Random -Access Traversal Iterator and Readable Iterator and Writable -Iterator. - -======== - Design -======== - -The iterator requirements are to be separated into two groups. One set -of concepts handles the syntax and semantics of value access: - -- Readable Iterator -- Writable Iterator -- Swappable Iterator -- Lvalue Iterator - -The access concepts describe requirements related to ``operator*`` and -``operator->``, including the ``value_type``, ``reference``, and -``pointer`` associated types. - -The other set of concepts handles traversal: - -- Incrementable Iterator -- Single Pass Iterator -- Forward Traversal Iterator -- Bidirectional Traversal Iterator -- Random Access Traversal Iterator - -The refinement relationships for the traversal concepts are in the -following diagram. - -.. image:: traversal.png - -In addition to the iterator movement operators, such as -``operator++``, the traversal concepts also include requirements on -position comparison such as ``operator==`` and ``operator<``. The -reason for the fine grain slicing of the concepts into the -Incrementable and Single Pass is to provide concepts that are exact -matches with the original input and output iterator requirements. - -This proposal also includes a concept for specifying when an iterator -is interoperable with another iterator, in the sense that ``int*`` is -interoperable with ``int const*``. - -- Interoperable Iterators - - -The relationship between the new iterator concepts and the old are -given in the following diagram. - -.. image:: oldeqnew.png - -Like the old iterator requirements, we provide tags for purposes of -dispatching based on the traversal concepts. The tags are related via -inheritance so that a tag is convertible to another tag if the concept -associated with the first tag is a refinement of the second tag. - -Our design reuses ``iterator_traits::iterator_category`` to -indicate an iterator's traversal capability. To specify -capabilities not captured by any old-style iterator category, an -iterator designer can use an ``iterator_category`` type that is -convertible to both the the most-derived old iterator category tag -which 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 the -access concepts, in part because we could not find a way to -automatically infer the right access tags for old-style iterators. -An iterator's writability may be dependent on the assignability of -its ``value_type`` and there's no known way to detect whether an -arbitrary type is assignable. Fortunately, the need for -dispatching based on access capability is not as great as the need -for dispatching based on traversal capability. - -A difficult design decision concerned the ``operator[]``. The direct -approach for specifying ``operator[]`` would have a return type of -``reference``; the same as ``operator*``. However, going in this -direction would mean that an iterator satisfying the old Random Access -Iterator requirements would not necessarily be a model of Readable or -Writable Lvalue Iterator. Instead we have chosen a design that -matches the preferred resolution of `issue 299`_: ``operator[]`` is -only 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 constant -object of type ``X``, ``R`` is -``std::iterator_traits::reference``, ``T`` is -``std::iterator_traits::value_type``, and ``v`` is a constant -object of type ``T``. - -.. _Readable Iterator: - -Readable Iterators [lib.readable.iterators] -------------------------------------------- - -A class or built-in type ``X`` models the *Readable Iterator* concept -for value type ``T`` if, in addition to ``X`` being Assignable and -Copy Constructible, the following expressions are valid and respect -the stated semantics. ``U`` is the type of any specified member of -type ``T``. - -+-----------------------------------------------------------------------------------------------------------------------------+ -|Readable Iterator Requirements (in addition to Assignable and Copy Constructible) | -+-----------------------------------+------------------------+----------------------------------------------------------------+ -|Expression |Return Type |Note/Precondition | -+===================================+========================+================================================================+ -|``iterator_traits::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::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* concept -if, in addition to ``X`` being Copy Constructible, the following -expressions are valid and respect the stated semantics. Writable -Iterators 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* concept -if, in addition to ``X`` being Copy Constructible, the following -expressions 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 *Swappable -Iterator*. *--end note*] - - -Lvalue Iterators [lib.lvalue.iterators] ---------------------------------------- - -The *Lvalue Iterator* concept adds the requirement that the return -type of ``operator*`` type be a reference to the value type of the -iterator. - -+-------------------------------------------------------------+ -| Lvalue Iterator Requirements | -+-------------+-----------+-----------------------------------+ -|Expression |Return Type|Note/Assertion | -+=============+===========+===================================+ -|``*a`` | ``T&`` |``T`` is *cv* | -| | |``iterator_traits::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 `Readable -Iterator`_ 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`` are -constant objects of type ``X``, ``r`` and ``s`` are mutable objects of -type ``X``, ``T`` is ``std::iterator_traits::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 Copy -Constructible, the following expressions are valid and respect the -stated semantics. - -+------------------------------------------------------------------------------------+ -|Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible) | -| | -+--------------------------------+-------------------------------+-------------------+ -|Expression |Return Type |Assertion | -+================================+===============================+===================+ -|``++r`` |``X&`` |``&r == &++r`` | -+--------------------------------+-------------------------------+-------------------+ -|``r++`` | | | -+--------------------------------+-------------------------------+-------------------+ -|``*r++`` | | | -+--------------------------------+-------------------------------+-------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``incrementable_traversal_tag``| | -+--------------------------------+-------------------------------+-------------------+ - - -If ``X`` is a `Writable Iterator`_ then ``X a(r++);`` is equivalent -to ``X a(r); ++r;`` and ``*r++ = o`` is equivalent -to ``*r = o; ++r``. -If ``X`` is a `Readable Iterator`_ then ``T z(*r++);`` is equivalent -to ``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 stated -semantics. - - -+--------------------------------------------------------------------------------------------------------+ -|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_traversal::type`` |Convertible to | | | -| |``single_pass_traversal_tag``| | | -+--------------------------------+-----------------------------+-------------+---------------------------+ - -.. TR1: single_pass_iterator_tag changed to - single_pass_traversal_tag for consistency - - -Forward 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 Default -Constructible and Single Pass Iterator, the following expressions are -valid and respect the stated semantics. - -+--------------------------------------------------------------------------------------------------------+ -|Forward Traversal Iterator Requirements (in addition to Default Constructible and Single Pass Iterator) | -+---------------------------------------+-----------------------------------+----------------------------+ -|Expression |Return Type |Assertion/Note | -+=======================================+===================================+============================+ -|``X u;`` |``X&`` |note: ``u`` may have a | -| | |singular value. | -+---------------------------------------+-----------------------------------+----------------------------+ -|``++r`` |``X&`` |``r == s`` and ``r`` is | -| | |dereferenceable implies | -| | |``++r == ++s.`` | -+---------------------------------------+-----------------------------------+----------------------------+ -|``iterator_traits::difference_type``|A signed integral type representing| | -| |the distance between iterators | | -| | | | -+---------------------------------------+-----------------------------------+----------------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``forward_traversal_tag`` | | -+---------------------------------------+-----------------------------------+----------------------------+ - - - -.. TR1: forward_traversal_iterator_tag changed to - forward_traversal_tag for consistency - - -Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators] -------------------------------------------------------------------------- - -A class or built-in type ``X`` models the *Bidirectional Traversal -Iterator* concept if, in addition to ``X`` meeting the requirements of -Forward Traversal Iterator, the following expressions are valid and -respect the stated semantics. - -+-----------------------------------------------------------------------------------------------------+ -|Bidirectional Traversal Iterator Requirements (in addition to Forward Traversal | -|Iterator) | -+--------------------------------+-------------------------------+--------------+---------------------+ -|Expression |Return Type | Operational |Assertion/ | -| | | Semantics |Pre-/Post-condition | -+================================+===============================+==============+=====================+ -|``--r`` |``X&`` | |pre: there exists | -| | | |``s`` such that ``r | -| | | |== ++s``. post: | -| | | |``s`` is | -| | | |dereferenceable. | -| | | | | -| | | |``++(--r) == r``. | -| | | |``--r == --s`` | -| | | |implies ``r == | -| | | |s``. ``&r == &--r``. | -+--------------------------------+-------------------------------+--------------+---------------------+ -|``r--`` |convertible to ``const X&`` |:: | | -| | | | | -| | | { | | -| | | X tmp = r; | | -| | | --r; | | -| | | return tmp;| | -| | | } | | -+--------------------------------+-------------------------------+--------------+---------------------+ -|``iterator_traversal::type`` |Convertible to | | | -| |``bidirectional_traversal_tag``| | | -| | | | | -+--------------------------------+-------------------------------+--------------+---------------------+ - -.. TR1: bidirectional_traversal_iterator_tag changed to - bidirectional_traversal_tag for consistency - -Random Access Traversal Iterators [lib.random.access.traversal.iterators] -------------------------------------------------------------------------- - -A class or built-in type ``X`` models the *Random Access Traversal -Iterator* concept if the following expressions are valid and respect -the stated semantics. In the table below, ``Distance`` is -``iterator_traits::difference_type`` and ``n`` represents a -constant object of type ``Distance``. - -+------------------------------------------------------------------------------------------------------------------+ -|Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal Iterator) | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|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::type``|Convertible to | | | -| |``random_access_traversal_tag`` | | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ - -.. TR1: random_access_traversal_iterator_tag changed to - random_access_traversal_tag for consistency - - -Interoperable Iterators [lib.interoperable.iterators] ------------------------------------------------------ - -A class or built-in type ``X`` that models Single Pass Iterator is -*interoperable with* a class or built-in type ``Y`` that also models -Single Pass Iterator if the following expressions are valid and -respect the stated semantics. In the tables below, ``x`` is an object -of type ``X``, ``y`` is an object of type ``Y``, ``Distance`` is -``iterator_traits::difference_type``, and ``n`` represents a -constant object of type ``Distance``. - -+-----------+-----------------------+---------------------------------------------------+ -|Expression |Return Type |Assertion/Precondition/Postcondition | -+===========+=======================+===================================================+ -|``y = x`` |``Y`` |post: ``y == x`` | -+-----------+-----------------------+---------------------------------------------------+ -|``Y(x)`` |``Y`` |post: ``Y(x) == x`` | -+-----------+-----------------------+---------------------------------------------------+ -|``x == y`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``y == x`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``x != y`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``y != x`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | -+-----------+-----------------------+---------------------------------------------------+ - -If ``X`` and ``Y`` both model Random Access Traversal Iterator then -the following additional requirements must be met. - -+-----------+-----------------------+---------------------+--------------------------------------+ -|Expression |Return Type |Operational Semantics|Assertion/ Precondition | -+===========+=======================+=====================+======================================+ -|``x < y`` |convertible to ``bool``|``y - x > 0`` |``<`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y < x`` |convertible to ``bool``|``x - y > 0`` |``<`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x > y`` |convertible to ``bool``|``y < x`` |``>`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y > x`` |convertible to ``bool``|``x < y`` |``>`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x >= y`` |convertible to ``bool``|``!(x < y)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y >= x`` |convertible to ``bool``|``!(y < x)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x <= y`` |convertible to ``bool``|``!(x > y)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y <= x`` |convertible to ``bool``|``!(y > x)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y - x`` |``Distance`` |``distance(Y(x),y)`` |pre: there exists a value ``n`` of | -| | | |``Distance`` such that ``x + n == y``.| -| | | |``y == x + (y - x)``. | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x - y`` |``Distance`` |``distance(y,Y(x))`` |pre: there exists a value ``n`` of | -| | | |``Distance`` such that ``y + n == x``.| -| | | |``x == y + (x - y)``. | -+-----------+-----------------------+---------------------+--------------------------------------+ - - - -Addition to [lib.iterator.synopsis] -=================================== - - -:: - - // lib.iterator.traits, traits and tags - template struct is_readable_iterator; - template struct iterator_traversal; - - struct incrementable_traversal_tag { }; - struct single_pass_traversal_tag : incrementable_traversal_tag { }; - struct forward_traversal_tag : single_pass_traversal_tag { }; - struct bidirectional_traversal_tag : forward_traversal_tag { }; - struct random_access_traversal_tag : bidirectional_traversal_tag { }; - -Addition to [lib.iterator.traits] -================================= - -The ``is_readable_iterator`` class -template satisfies the UnaryTypeTrait_ requirements. - -Given an iterator type ``X``, ``is_readable_iterator::value`` -yields ``true`` if, for an object ``a`` of type ``X``, ``*a`` is -convertible to ``iterator_traits::value_type``, and ``false`` -otherwise. - -``iterator_traversal::type`` is - -.. parsed-literal:: - - *category-to-traversal*\ (iterator_traits::iterator_category) - -where *category-to-traversal* is defined as follows - -.. _`category-to-traversal`: - -.. parsed-literal:: - - *category-to-traversal*\ (C) = - if (C is convertible to incrementable_traversal_tag) - return C; - else if (C is convertible to random_access_iterator_tag) - return random_access_traversal_tag; - else if (C is convertible to bidirectional_iterator_tag) - return bidirectional_traversal_tag; - else if (C is convertible to forward_iterator_tag) - return forward_traversal_tag; - else if (C is convertible to input_iterator_tag) - return single_pass_traversal_tag; - else if (C is convertible to output_iterator_tag) - return incrementable_traversal_tag; - else - *the program is ill-formed* - - -=========== - Footnotes -=========== - -.. _UnaryTypeTrait: n1519_ - -The UnaryTypeTrait concept is defined in n1519_; the LWG is -considering adding the requirement that specializations are derived -from their nested ``::type``. - -.. _n1519: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1519.htm - -.. - LocalWords: Abrahams Siek Witt const bool Sutter's WG int UL LI href Lvalue - LocalWords: ReadableIterator WritableIterator SwappableIterator cv pre iter - LocalWords: ConstantLvalueIterator MutableLvalueIterator CopyConstructible TR - LocalWords: ForwardTraversalIterator BidirectionalTraversalIterator lvalue - LocalWords: RandomAccessTraversalIterator dereferenceable Incrementable tmp - LocalWords: incrementable xxx min prev inplace png oldeqnew AccessTag struct - LocalWords: TraversalTag typename lvalues DWA Hmm JGS mis enum diff --git a/doc/oldeqnew.png b/doc/oldeqnew.png deleted file mode 100644 index 30cd159..0000000 Binary files a/doc/oldeqnew.png and /dev/null differ diff --git a/doc/permutation_iter_abstract.rst b/doc/permutation_iter_abstract.rst deleted file mode 100644 index 787c51a..0000000 --- a/doc/permutation_iter_abstract.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. 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) - -The permutation iterator adaptor provides a permuted view of a given -range. That is, the view includes every element of the given range but -in a potentially different order. - diff --git a/doc/permutation_iterator.html b/doc/permutation_iterator.html deleted file mode 100644 index 160cf21..0000000 --- a/doc/permutation_iterator.html +++ /dev/null @@ -1,587 +0,0 @@ - - - - - - -Permutation Iterator - - - - - - - -
-

Permutation Iterator

- --- - - - - - - - - - - - -
Author:Toon Knapen, David Abrahams, Roland Richter, Jeremy Siek
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu
Organization:Boost Consulting, Indiana University Open Systems -Lab
Date:2004-11-01
Copyright:Copyright Toon Knapen, David Abrahams, Roland Richter, and Jeremy Siek 2003.
- - - - --- - - - -
abstract: - - -The permutation iterator adaptor provides a permuted view of a given -range. That is, the view includes every element of the given range but -in a potentially different order.
- -
-

Introduction

- - - -

The adaptor takes two arguments:

-
-
    -
  • an iterator to the range V on which the permutation -will be applied
  • -
  • the reindexing scheme that defines how the -elements of V will be permuted.
  • -
-
-

Note that the permutation iterator is not limited to strict -permutations of the given range V. The distance between begin and end -of the reindexing iterators is allowed to be smaller compared to the -size of the range V, in which case the permutation iterator only -provides a permutation of a subrange of V. The indexes neither need -to be unique. In this same context, it must be noted that the past the -end permutation iterator is completely defined by means of the -past-the-end iterator to the indices.

-
-
-

Reference

- - - -
-template< class ElementIterator
-        , class IndexIterator
-        , class ValueT        = use_default
-        , class CategoryT     = use_default
-        , class ReferenceT    = use_default
-        , class DifferenceT   = use_default >
-class permutation_iterator
-{
-public:
-  permutation_iterator();
-  explicit permutation_iterator(ElementIterator x, IndexIterator y);
-
-  template< class OEIter, class OIIter, class V, class C, class R, class D >
-  permutation_iterator(
-      permutation_iterator<OEIter, OIIter, V, C, R, D> const& r
-      , typename enable_if_convertible<OEIter, ElementIterator>::type* = 0
-      , typename enable_if_convertible<OIIter, IndexIterator>::type* = 0
-      );
-  reference operator*() const;
-  permutation_iterator& operator++();
-  ElementIterator const& base() const;
-private:
-  ElementIterator m_elt;      // exposition only
-  IndexIterator m_order;      // exposition only
-};
-
-template <class ElementIterator, class IndexIterator>
-permutation_iterator<ElementIterator, IndexIterator>
-make_permutation_iterator( ElementIterator e, IndexIterator i);
-
-
-

permutation_iterator requirements

-

ElementIterator shall model Random Access Traversal Iterator. -IndexIterator shall model Readable Iterator. The value type of -the IndexIterator must be convertible to the difference type of -ElementIterator.

-
-
-

permutation_iterator models

-

permutation_iterator models the same iterator traversal concepts -as IndexIterator and the same iterator access concepts as -ElementIterator.

-

If IndexIterator models Single Pass Iterator and -ElementIterator models Readable Iterator then -permutation_iterator models Input Iterator.

-

If IndexIterator models Forward Traversal Iterator and -ElementIterator models Readable Lvalue Iterator then -permutation_iterator models Forward Iterator.

-

If IndexIterator models Bidirectional Traversal Iterator and -ElementIterator models Readable Lvalue Iterator then -permutation_iterator models Bidirectional Iterator.

-

If IndexIterator models Random Access Traversal Iterator and -ElementIterator models Readable Lvalue Iterator then -permutation_iterator models Random Access Iterator.

-

permutation_iterator<E1, X, V1, C2, R1, D1> is interoperable -with permutation_iterator<E2, Y, V2, C2, R2, D2> if and only if -X is interoperable with Y and E1 is convertible -to E2.

-
-
-

permutation_iterator operations

-

In addition to those operations required by the concepts that -permutation_iterator models, permutation_iterator provides the -following operations.

-

permutation_iterator();

- --- - - - -
Effects:Default constructs m_elt and m_order.
-

explicit permutation_iterator(ElementIterator x, IndexIterator y);

- --- - - - -
Effects:Constructs m_elt from x and m_order from y.
-
-template< class OEIter, class OIIter, class V, class C, class R, class D >
-permutation_iterator(
-    permutation_iterator<OEIter, OIIter, V, C, R, D> const& r
-    , typename enable_if_convertible<OEIter, ElementIterator>::type* = 0
-    , typename enable_if_convertible<OIIter, IndexIterator>::type* = 0
-    );
-
- --- - - - -
Effects:Constructs m_elt from r.m_elt and -m_order from y.m_order.
-

reference operator*() const;

- --- - - - -
Returns:*(m_elt + *m_order)
-

permutation_iterator& operator++();

- --- - - - - - -
Effects:++m_order
Returns:*this
-

ElementIterator const& base() const;

- --- - - - -
Returns:m_order
-
-template <class ElementIterator, class IndexIterator>
-permutation_iterator<ElementIterator, IndexIterator>
-make_permutation_iterator(ElementIterator e, IndexIterator i);
-
- --- - - - -
Returns:permutation_iterator<ElementIterator, IndexIterator>(e, i)
-
-
-
-

Example

- - - -
-using namespace boost;
-int i = 0;
-
-typedef std::vector< int > element_range_type;
-typedef std::list< int > index_type;
-
-static const int element_range_size = 10;
-static const int index_size = 4;
-
-element_range_type elements( element_range_size );
-for(element_range_type::iterator el_it = elements.begin() ; el_it != elements.end() ; ++el_it)
-  *el_it = std::distance(elements.begin(), el_it);
-
-index_type indices( index_size );
-for(index_type::iterator i_it = indices.begin() ; i_it != indices.end() ; ++i_it )
-  *i_it = element_range_size - index_size + std::distance(indices.begin(), i_it);
-std::reverse( indices.begin(), indices.end() );
-
-typedef permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type;
-permutation_type begin = make_permutation_iterator( elements.begin(), indices.begin() );
-permutation_type it = begin;
-permutation_type end = make_permutation_iterator( elements.begin(), indices.end() );
-
-std::cout << "The original range is : ";
-std::copy( elements.begin(), elements.end(), std::ostream_iterator< int >( std::cout, " " ) );
-std::cout << "\n";
-
-std::cout << "The reindexing scheme is : ";
-std::copy( indices.begin(), indices.end(), std::ostream_iterator< int >( std::cout, " " ) );
-std::cout << "\n";
-
-std::cout << "The permutated range is : ";
-std::copy( begin, end, std::ostream_iterator< int >( std::cout, " " ) );
-std::cout << "\n";
-
-std::cout << "Elements at even indices in the permutation : ";
-it = begin;
-for(i = 0; i < index_size / 2 ; ++i, it+=2 ) std::cout << *it << " ";
-std::cout << "\n";
-
-std::cout << "Permutation backwards : ";
-it = begin + (index_size);
-assert( it != begin );
-for( ; it-- != begin ; ) std::cout << *it << " ";
-std::cout << "\n";
-
-std::cout << "Iterate backward with stride 2 : ";
-it = begin + (index_size - 1);
-for(i = 0 ; i < index_size / 2 ; ++i, it-=2 ) std::cout << *it << " ";
-std::cout << "\n";
-
-

The output is:

-
-The original range is : 0 1 2 3 4 5 6 7 8 9
-The reindexing scheme is : 9 8 7 6
-The permutated range is : 9 8 7 6
-Elements at even indices in the permutation : 9 7
-Permutation backwards : 6 7 8 9
-Iterate backward with stride 2 : 6 8
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/permutation_iterator.pdf b/doc/permutation_iterator.pdf deleted file mode 100755 index 3f69d1d..0000000 Binary files a/doc/permutation_iterator.pdf and /dev/null differ diff --git a/doc/permutation_iterator.rst b/doc/permutation_iterator.rst deleted file mode 100644 index 0c8070c..0000000 --- a/doc/permutation_iterator.rst +++ /dev/null @@ -1,41 +0,0 @@ -.. 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) - -++++++++++++++++++++++ - Permutation Iterator -++++++++++++++++++++++ - -:Author: Toon Knapen, David Abrahams, Roland Richter, Jeremy Siek -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_ -:date: $Date$ -:copyright: Copyright Toon Knapen, David Abrahams, Roland Richter, and Jeremy Siek 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu - -:abstract: - - .. include:: permutation_iter_abstract.rst - -.. contents:: Table of Contents - - -Introduction -============ - -.. include:: permutation_iterator_body.rst - - -Reference -========= - -.. include:: permutation_iterator_ref.rst - - -Example -======= - -.. include:: permutation_iterator_eg.rst diff --git a/doc/permutation_iterator_body.rst b/doc/permutation_iterator_body.rst deleted file mode 100644 index 8b1333c..0000000 --- a/doc/permutation_iterator_body.rst +++ /dev/null @@ -1,19 +0,0 @@ -.. 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) - -The adaptor takes two arguments: - - * an iterator to the range V on which the permutation - will be applied - * the reindexing scheme that defines how the - elements of V will be permuted. - -Note that the permutation iterator is not limited to strict -permutations of the given range V. The distance between begin and end -of the reindexing iterators is allowed to be smaller compared to the -size of the range V, in which case the permutation iterator only -provides a permutation of a subrange of V. The indexes neither need -to be unique. In this same context, it must be noted that the past the -end permutation iterator is completely defined by means of the -past-the-end iterator to the indices. diff --git a/doc/permutation_iterator_eg.rst b/doc/permutation_iterator_eg.rst deleted file mode 100644 index eddf0a1..0000000 --- a/doc/permutation_iterator_eg.rst +++ /dev/null @@ -1,71 +0,0 @@ -.. 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) - -:: - - using namespace boost; - int i = 0; - - typedef std::vector< int > element_range_type; - typedef std::list< int > index_type; - - static const int element_range_size = 10; - static const int index_size = 4; - - element_range_type elements( element_range_size ); - for(element_range_type::iterator el_it = elements.begin() ; el_it != elements.end() ; ++el_it) - *el_it = std::distance(elements.begin(), el_it); - - index_type indices( index_size ); - for(index_type::iterator i_it = indices.begin() ; i_it != indices.end() ; ++i_it ) - *i_it = element_range_size - index_size + std::distance(indices.begin(), i_it); - std::reverse( indices.begin(), indices.end() ); - - typedef permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type; - permutation_type begin = make_permutation_iterator( elements.begin(), indices.begin() ); - permutation_type it = begin; - permutation_type end = make_permutation_iterator( elements.begin(), indices.end() ); - - std::cout << "The original range is : "; - std::copy( elements.begin(), elements.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The reindexing scheme is : "; - std::copy( indices.begin(), indices.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The permutated range is : "; - std::copy( begin, end, std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "Elements at even indices in the permutation : "; - it = begin; - for(i = 0; i < index_size / 2 ; ++i, it+=2 ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Permutation backwards : "; - it = begin + (index_size); - assert( it != begin ); - for( ; it-- != begin ; ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Iterate backward with stride 2 : "; - it = begin + (index_size - 1); - for(i = 0 ; i < index_size / 2 ; ++i, it-=2 ) std::cout << *it << " "; - std::cout << "\n"; - - -The output is:: - - The original range is : 0 1 2 3 4 5 6 7 8 9 - The reindexing scheme is : 9 8 7 6 - The permutated range is : 9 8 7 6 - Elements at even indices in the permutation : 9 7 - Permutation backwards : 6 7 8 9 - Iterate backward with stride 2 : 6 8 - - -The source code for this example can be found `here`__. - -__ ../example/permutation_iter_example.cpp diff --git a/doc/permutation_iterator_ref.rst b/doc/permutation_iterator_ref.rst deleted file mode 100644 index d51864f..0000000 --- a/doc/permutation_iterator_ref.rst +++ /dev/null @@ -1,130 +0,0 @@ -.. 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) - -.. parsed-literal:: - - template< class ElementIterator - , class IndexIterator - , class ValueT = use_default - , class CategoryT = use_default - , class ReferenceT = use_default - , class DifferenceT = use_default > - class permutation_iterator - { - public: - permutation_iterator(); - explicit permutation_iterator(ElementIterator x, IndexIterator y); - - template< class OEIter, class OIIter, class V, class C, class R, class D > - permutation_iterator( - permutation_iterator const& r - , typename enable_if_convertible::type* = 0 - , typename enable_if_convertible::type* = 0 - ); - reference operator*() const; - permutation_iterator& operator++(); - ElementIterator const& base() const; - private: - ElementIterator m_elt; // exposition only - IndexIterator m_order; // exposition only - }; - - template - permutation_iterator - make_permutation_iterator( ElementIterator e, IndexIterator i); - - - -``permutation_iterator`` requirements -------------------------------------- - -``ElementIterator`` shall model Random Access Traversal Iterator. -``IndexIterator`` shall model Readable Iterator. The value type of -the ``IndexIterator`` must be convertible to the difference type of -``ElementIterator``. - - -``permutation_iterator`` models -------------------------------- - -``permutation_iterator`` models the same iterator traversal concepts -as ``IndexIterator`` and the same iterator access concepts as -``ElementIterator``. - -If ``IndexIterator`` models Single Pass Iterator and -``ElementIterator`` models Readable Iterator then -``permutation_iterator`` models Input Iterator. - -If ``IndexIterator`` models Forward Traversal Iterator and -``ElementIterator`` models Readable Lvalue Iterator then -``permutation_iterator`` models Forward Iterator. - -If ``IndexIterator`` models Bidirectional Traversal Iterator and -``ElementIterator`` models Readable Lvalue Iterator then -``permutation_iterator`` models Bidirectional Iterator. - -If ``IndexIterator`` models Random Access Traversal Iterator and -``ElementIterator`` models Readable Lvalue Iterator then -``permutation_iterator`` models Random Access Iterator. - -``permutation_iterator`` is interoperable -with ``permutation_iterator`` if and only if -``X`` is interoperable with ``Y`` and ``E1`` is convertible -to ``E2``. - - -``permutation_iterator`` operations ------------------------------------ - -In addition to those operations required by the concepts that -``permutation_iterator`` models, ``permutation_iterator`` provides the -following operations. - -``permutation_iterator();`` - -:Effects: Default constructs ``m_elt`` and ``m_order``. - - -``explicit permutation_iterator(ElementIterator x, IndexIterator y);`` - -:Effects: Constructs ``m_elt`` from ``x`` and ``m_order`` from ``y``. - - -:: - - template< class OEIter, class OIIter, class V, class C, class R, class D > - permutation_iterator( - permutation_iterator const& r - , typename enable_if_convertible::type* = 0 - , typename enable_if_convertible::type* = 0 - ); - -:Effects: Constructs ``m_elt`` from ``r.m_elt`` and - ``m_order`` from ``y.m_order``. - - -``reference operator*() const;`` - -:Returns: ``*(m_elt + *m_order)`` - - -``permutation_iterator& operator++();`` - -:Effects: ``++m_order`` -:Returns: ``*this`` - - -``ElementIterator const& base() const;`` - -:Returns: ``m_order`` - - -:: - - template - permutation_iterator - make_permutation_iterator(ElementIterator e, IndexIterator i); - -:Returns: ``permutation_iterator(e, i)`` - diff --git a/doc/pointee.html b/doc/pointee.html deleted file mode 100755 index d7ca6e3..0000000 --- a/doc/pointee.html +++ /dev/null @@ -1,459 +0,0 @@ - - - - - - -pointee and indirect_reference - - - - - - - -
-

pointee and indirect_reference

- --- - - - - - - - - - - - -
Author:David Abrahams
Contact:dave@boost-consulting.com
Organization:Boost Consulting
Date:2005-02-27
Copyright:Copyright David Abrahams 2004.
- - - - --- - - - -
abstract:Provides the capability to deduce the referent types of -pointers, smart pointers and iterators in generic code.
-
-

Overview

-

Have you ever wanted to write a generic function that can operate -on any kind of dereferenceable object? If you have, you've -probably run into the problem of how to determine the type that the -object "points at":

-
-template <class Dereferenceable>
-void f(Dereferenceable p)
-{
-    what-goes-here? value = *p;
-    ...
-}
-
-
-

pointee

-

It turns out to be impossible to come up with a fully-general -algorithm to do determine what-goes-here directly, but it is -possible to require that pointee<Dereferenceable>::type is -correct. Naturally, pointee has the same difficulty: it can't -determine the appropriate ::type reliably for all -Dereferenceables, but it makes very good guesses (it works -for all pointers, standard and boost smart pointers, and -iterators), and when it guesses wrongly, it can be specialized as -necessary:

-
-namespace boost
-{
-  template <class T>
-  struct pointee<third_party_lib::smart_pointer<T> >
-  {
-      typedef T type;
-  };
-}
-
-
-
-

indirect_reference

-

indirect_reference<T>::type is rather more specialized than -pointee, and is meant to be used to forward the result of -dereferencing an object of its argument type. Most dereferenceable -types just return a reference to their pointee, but some return -proxy references or return the pointee by value. When that -information is needed, call on indirect_reference.

-

Both of these templates are essential to the correct functioning of -indirect_iterator.

-
-
-
-

Reference

-
-

pointee

- - - -
-template <class Dereferenceable>
-struct pointee
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -Dereferenceable::element_type shall be an accessible type. -Otherwise iterator_traits<Dereferenceable>::value_type shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of pointee]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-{
-    return ``Dereferenceable::element_type``
-}
-else if (``*x`` is a mutable reference to
-         std::iterator_traits<Dereferenceable>::value_type)
-{
-    return iterator_traits<Dereferenceable>::value_type
-}
-else
-{
-    return iterator_traits<Dereferenceable>::value_type const
-}
-
-
-
-

indirect_reference

- - - -
-template <class Dereferenceable>
-struct indirect_reference
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -pointee<Dereferenceable>::type& shall be well-formed. -Otherwise iterator_traits<Dereferenceable>::reference shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of indirect_reference]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-    return ``pointee<Dereferenceable>::type&``
-else
-    std::iterator_traits<Dereferenceable>::reference
-
-
-
-
- - diff --git a/doc/pointee.pdf b/doc/pointee.pdf deleted file mode 100755 index 53f9f6d..0000000 Binary files a/doc/pointee.pdf and /dev/null differ diff --git a/doc/pointee.rst b/doc/pointee.rst deleted file mode 100755 index 993c3d4..0000000 --- a/doc/pointee.rst +++ /dev/null @@ -1,88 +0,0 @@ -.. 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) - -++++++++++++++++++++++++++++++++++++++++ - ``pointee`` and ``indirect_reference`` -++++++++++++++++++++++++++++++++++++++++ - -:Author: David Abrahams -:Contact: dave@boost-consulting.com -:organization: `Boost Consulting`_ -:date: $Date$ -:copyright: Copyright David Abrahams 2004. - -.. _`Boost Consulting`: http://www.boost-consulting.com - -:abstract: Provides the capability to deduce the referent types of - pointers, smart pointers and iterators in generic code. - -Overview -======== - -Have you ever wanted to write a generic function that can operate -on any kind of dereferenceable object? If you have, you've -probably run into the problem of how to determine the type that the -object "points at": - -.. parsed-literal:: - - template - void f(Dereferenceable p) - { - *what-goes-here?* value = \*p; - ... - } - - -``pointee`` ------------ - -It turns out to be impossible to come up with a fully-general -algorithm to do determine *what-goes-here* directly, but it is -possible to require that ``pointee::type`` is -correct. Naturally, ``pointee`` has the same difficulty: it can't -determine the appropriate ``::type`` reliably for all -``Dereferenceable``\ s, but it makes very good guesses (it works -for all pointers, standard and boost smart pointers, and -iterators), and when it guesses wrongly, it can be specialized as -necessary:: - - namespace boost - { - template - struct pointee > - { - typedef T type; - }; - } - -``indirect_reference`` ----------------------- - -``indirect_reference::type`` is rather more specialized than -``pointee``, and is meant to be used to forward the result of -dereferencing an object of its argument type. Most dereferenceable -types just return a reference to their pointee, but some return -proxy references or return the pointee by value. When that -information is needed, call on ``indirect_reference``. - -Both of these templates are essential to the correct functioning of -|indirect_iterator|_. - -.. |indirect_iterator| replace:: ``indirect_iterator`` -.. _indirect_iterator: indirect_iterator.html - -Reference -========= - -``pointee`` ------------ - -.. include:: pointee_ref.rst - -``indirect_reference`` ----------------------- - -.. include:: indirect_reference_ref.rst - diff --git a/doc/pointee_ref.rst b/doc/pointee_ref.rst deleted file mode 100755 index 19aed24..0000000 --- a/doc/pointee_ref.rst +++ /dev/null @@ -1,38 +0,0 @@ -.. Copyright David Abrahams 2004. Use, modification and distribution is -.. subject to 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) - -:: - - template - struct pointee - { - typedef /* see below */ type; - }; - -:Requires: For an object ``x`` of type ``Dereferenceable``, ``*x`` - is well-formed. If ``++x`` is ill-formed it shall neither be - ambiguous nor shall it violate access control, and - ``Dereferenceable::element_type`` shall be an accessible type. - Otherwise ``iterator_traits::value_type`` shall - be well formed. [Note: These requirements need not apply to - explicit or partial specializations of ``pointee``] - -``type`` is determined according to the following algorithm, where -``x`` is an object of type ``Dereferenceable``:: - - if ( ++x is ill-formed ) - { - return ``Dereferenceable::element_type`` - } - else if (``*x`` is a mutable reference to - std::iterator_traits::value_type) - { - return iterator_traits::value_type - } - else - { - return iterator_traits::value_type const - } - - \ No newline at end of file diff --git a/doc/ref_problem.rst b/doc/ref_problem.rst deleted file mode 100644 index 2f2908a..0000000 --- a/doc/ref_problem.rst +++ /dev/null @@ -1,63 +0,0 @@ -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Problem with ``reference`` and old/new iterator category correspondance -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. _N1550: http://www.boost-consulting.com/writing/n1550.html -.. _N1530: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html - -:Author: David Abrahams and Jeremy Siek -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu -:Organization: `Boost Consulting`_, Indiana University Bloomington -:date: $Date$ -:Copyright: Copyright David Abrahams, Jeremy Siek 2003. Use, modification and - distribution is subject to 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) - -.. _`Boost Consulting`: http://www.boost-consulting.com - -============== - Introduction -============== - -The new iterator categories are intended to correspond to the old -iterator categories, as specified in a diagram in N1550_. For example, -an iterator categorized as a mutable Forward Iterator under the old -scheme is now a Writable, Lvalue, and Foward Traversal iterator. -However, there is a problem with this correspondance, the new iterator -categories place requirements on the ``iterator_traits::reference`` -type whereas the standard iterator requirements say nothing about the -``reference`` type . In particular, the new Readable Iterator -requirements say that the return type of ``*a`` must be -``iterator_traits::reference`` and the Lvalue Iterator requirements -says that ``iterator_traits::reference`` must be ``T&`` or ``const -T&``. - - -==================== - Proposed Resolution -==================== - -Change the standard requirements to match the requirements of the new -iterators. (more details to come) - - -========== - Rationale -========== - -The lack of specification in the standard of the ``reference`` type is -certainly a defect. Without specification, it is entirely useless in a -generic function. The current practice in the community is generally -to assume there are requirements on the ``reference`` type, such as -those proposed in the new iterator categories. - -There is some danger in *adding* requirements to existing concepts. -This will mean that some existing iterator types will no longer meet -the iterator requirements. However, we feel that the impact of this is -small enough to warrant going ahead with this change. - -An alternative solution would be to leave the standard requirements as -is, and to remove the requirements for the ``reference`` type in the -new iterator concepts. We are not in favor of this approach because it -extends what we see as a defect further into the future. diff --git a/doc/reverse_iterator.html b/doc/reverse_iterator.html deleted file mode 100644 index aab1215..0000000 --- a/doc/reverse_iterator.html +++ /dev/null @@ -1,573 +0,0 @@ - - - - - - -Reverse Iterator - - - - - - - -
-

Reverse Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract: - - -The reverse iterator adaptor iterates through the adapted iterator -range in the opposite direction.
- -
-

reverse_iterator synopsis

- - - -
-template <class Iterator>
-class reverse_iterator
-{
-public:
-  typedef iterator_traits<Iterator>::value_type value_type;
-  typedef iterator_traits<Iterator>::reference reference;
-  typedef iterator_traits<Iterator>::pointer pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  reverse_iterator() {}
-  explicit reverse_iterator(Iterator x) ;
-
-  template<class OtherIterator>
-  reverse_iterator(
-      reverse_iterator<OtherIterator> const& r
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-  );
-  Iterator const& base() const;
-  reference operator*() const;
-  reverse_iterator& operator++();
-  reverse_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition
-};
-
-

If Iterator models Random Access Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -bidirectional_iterator_tag. Otherwise, iterator_category is -convertible to input_iterator_tag.

-
-
-

reverse_iterator requirements

-

Iterator must be a model of Bidirectional Traversal Iterator. The -type iterator_traits<Iterator>::reference must be the type of -*i, where i is an object of type Iterator.

-
-
-

reverse_iterator models

-

A specialization of reverse_iterator models the same iterator -traversal and iterator access concepts modeled by its Iterator -argument. In addition, it may model old iterator concepts -specified in the following table:

- ---- - - - - - - - - - - - - - - - - - - - -
If I modelsthen reverse_iterator<I> models
Readable Lvalue Iterator, -Bidirectional Traversal IteratorBidirectional Iterator
Writable Lvalue Iterator, -Bidirectional Traversal IteratorMutable Bidirectional Iterator
Readable Lvalue Iterator, -Random Access Traversal IteratorRandom Access Iterator
Writable Lvalue Iterator, -Random Access Traversal IteratorMutable Random Access Iterator
-

reverse_iterator<X> is interoperable with -reverse_iterator<Y> if and only if X is interoperable with -Y.

-
-
-

reverse_iterator operations

-

In addition to the operations required by the concepts modeled by -reverse_iterator, reverse_iterator provides the following -operations.

-

reverse_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of reverse_iterator with m_iterator -default constructed.
-

explicit reverse_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of reverse_iterator with -m_iterator copy constructed from x.
-
-template<class OtherIterator>
-reverse_iterator(
-    reverse_iterator<OtherIterator> const& r
-  , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs instance of reverse_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Effects:
-
-Iterator tmp = m_iterator;
-return *--tmp;
-
-

reverse_iterator& operator++();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-

reverse_iterator& operator--();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
- - - -
-template <class BidirectionalIterator>
-reverse_iterator<BidirectionalIterator>n
-make_reverse_iterator(BidirectionalIterator x);
-
- --- - - - -
Returns:An instance of reverse_iterator<BidirectionalIterator> -with a current constructed from x.
- - - -
-
-

Example

-

The following example prints an array of characters in reverse order -using reverse_iterator.

-
-char letters_[] = "hello world!";
-const int N = sizeof(letters_)/sizeof(char) - 1;
-typedef char* base_iterator;
-base_iterator letters(letters_);
-std::cout << "original sequence of letters:\t\t\t" << letters_ << std::endl;
-
-boost::reverse_iterator<base_iterator>
-  reverse_letters_first(letters + N),
-  reverse_letters_last(letters);
-
-std::cout << "sequence in reverse order:\t\t\t";
-std::copy(reverse_letters_first, reverse_letters_last,
-          std::ostream_iterator<char>(std::cout));
-std::cout << std::endl;
-
-std::cout << "sequence in double-reversed (normal) order:\t";
-std::copy(boost::make_reverse_iterator(reverse_letters_last),
-          boost::make_reverse_iterator(reverse_letters_first),
-          std::ostream_iterator<char>(std::cout));
-std::cout << std::endl;
-
-

The output is:

-
-original sequence of letters:                   hello world!
-sequence in reverse order:                      !dlrow olleh
-sequence in double-reversed (normal) order:     hello world!
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/reverse_iterator.pdf b/doc/reverse_iterator.pdf deleted file mode 100755 index 8cfd925..0000000 Binary files a/doc/reverse_iterator.pdf and /dev/null differ diff --git a/doc/reverse_iterator.rst b/doc/reverse_iterator.rst deleted file mode 100644 index e6034b6..0000000 --- a/doc/reverse_iterator.rst +++ /dev/null @@ -1,33 +0,0 @@ -.. 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) - -++++++++++++++++++ - Reverse Iterator -++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: reverse_iterator_abstract.rst - -.. contents:: Table of Contents - -``reverse_iterator`` synopsis -............................. - -.. include:: reverse_iterator_ref.rst -.. include:: make_reverse_iterator.rst - -.. include:: reverse_iterator_eg.rst diff --git a/doc/reverse_iterator_abstract.rst b/doc/reverse_iterator_abstract.rst deleted file mode 100644 index 911257f..0000000 --- a/doc/reverse_iterator_abstract.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. 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) - -The reverse iterator adaptor iterates through the adapted iterator -range in the opposite direction. - - - - - - diff --git a/doc/reverse_iterator_eg.rst b/doc/reverse_iterator_eg.rst deleted file mode 100644 index b17347e..0000000 --- a/doc/reverse_iterator_eg.rst +++ /dev/null @@ -1,45 +0,0 @@ -.. 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) - -Example -....... - -The following example prints an array of characters in reverse order -using ``reverse_iterator``. - -:: - - char letters_[] = "hello world!"; - const int N = sizeof(letters_)/sizeof(char) - 1; - typedef char* base_iterator; - base_iterator letters(letters_); - std::cout << "original sequence of letters:\t\t\t" << letters_ << std::endl; - - boost::reverse_iterator - reverse_letters_first(letters + N), - reverse_letters_last(letters); - - std::cout << "sequence in reverse order:\t\t\t"; - std::copy(reverse_letters_first, reverse_letters_last, - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - std::cout << "sequence in double-reversed (normal) order:\t"; - std::copy(boost::make_reverse_iterator(reverse_letters_last), - boost::make_reverse_iterator(reverse_letters_first), - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - - -The output is:: - - original sequence of letters: hello world! - sequence in reverse order: !dlrow olleh - sequence in double-reversed (normal) order: hello world! - - -The source code for this example can be found `here`__. - -__ ../example/reverse_iterator_example.cpp diff --git a/doc/reverse_iterator_ref.rst b/doc/reverse_iterator_ref.rst deleted file mode 100644 index b239b26..0000000 --- a/doc/reverse_iterator_ref.rst +++ /dev/null @@ -1,141 +0,0 @@ -.. 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) - -:: - - template - class reverse_iterator - { - public: - typedef iterator_traits::value_type value_type; - typedef iterator_traits::reference reference; - typedef iterator_traits::pointer pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - reverse_iterator() {} - explicit reverse_iterator(Iterator x) ; - - template - reverse_iterator( - reverse_iterator const& r - , typename enable_if_convertible::type* = 0 // exposition - ); - Iterator const& base() const; - reference operator*() const; - reverse_iterator& operator++(); - reverse_iterator& operator--(); - private: - Iterator m_iterator; // exposition - }; - - -If ``Iterator`` models Random Access Traversal Iterator and Readable -Lvalue Iterator, then ``iterator_category`` is convertible to -``random_access_iterator_tag``. Otherwise, if -``Iterator`` models Bidirectional Traversal Iterator and Readable -Lvalue Iterator, then ``iterator_category`` is convertible to -``bidirectional_iterator_tag``. Otherwise, ``iterator_category`` is -convertible to ``input_iterator_tag``. - - - -``reverse_iterator`` requirements -................................. - -``Iterator`` must be a model of Bidirectional Traversal Iterator. The -type ``iterator_traits::reference`` must be the type of -``*i``, where ``i`` is an object of type ``Iterator``. - - - -``reverse_iterator`` models -........................... - -A specialization of ``reverse_iterator`` models the same iterator -traversal and iterator access concepts modeled by its ``Iterator`` -argument. In addition, it may model old iterator concepts -specified in the following table: - -+---------------------------------------+-----------------------------------+ -| If ``I`` models |then ``reverse_iterator`` models| -+=======================================+===================================+ -| Readable Lvalue Iterator, | Bidirectional Iterator | -| Bidirectional Traversal Iterator | | -+---------------------------------------+-----------------------------------+ -| Writable Lvalue Iterator, | Mutable Bidirectional Iterator | -| Bidirectional Traversal Iterator | | -+---------------------------------------+-----------------------------------+ -| Readable Lvalue Iterator, | Random Access Iterator | -| Random Access Traversal Iterator | | -+---------------------------------------+-----------------------------------+ -| Writable Lvalue Iterator, | Mutable Random Access Iterator | -| Random Access Traversal Iterator | | -+---------------------------------------+-----------------------------------+ - - -``reverse_iterator`` is interoperable with -``reverse_iterator`` if and only if ``X`` is interoperable with -``Y``. - -``reverse_iterator`` operations -............................... - -In addition to the operations required by the concepts modeled by -``reverse_iterator``, ``reverse_iterator`` provides the following -operations. - - - -``reverse_iterator();`` - -:Requires: ``Iterator`` must be Default Constructible. -:Effects: Constructs an instance of ``reverse_iterator`` with ``m_iterator`` - default constructed. - -``explicit reverse_iterator(Iterator x);`` - -:Effects: Constructs an instance of ``reverse_iterator`` with - ``m_iterator`` copy constructed from ``x``. - - -:: - - template - reverse_iterator( - reverse_iterator const& r - , typename enable_if_convertible::type* = 0 // exposition - ); - -:Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. -:Effects: Constructs instance of ``reverse_iterator`` whose - ``m_iterator`` subobject is constructed from ``y.base()``. - - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - -``reference operator*() const;`` - -:Effects: - -:: - - Iterator tmp = m_iterator; - return *--tmp; - - -``reverse_iterator& operator++();`` - -:Effects: ``--m_iterator`` -:Returns: ``*this`` - - -``reverse_iterator& operator--();`` - -:Effects: ``++m_iterator`` -:Returns: ``*this`` diff --git a/doc/rst2html b/doc/rst2html deleted file mode 100755 index 82a7f1e..0000000 --- a/doc/rst2html +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# 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) -PYTHONPATH="c:/src/docutils;c:/src/docutils/extras" -export PYTHONPATH -python rst2html.py -gs $1 `echo $1 | sed 's/\(.*\)\..*/\1.html/'` - - - diff --git a/doc/rst2latex b/doc/rst2latex deleted file mode 100755 index f3c1d0e..0000000 --- a/doc/rst2latex +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -# 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) -PYTHONPATH="c:/src/docutils;c:/src/docutils/extras" -export PYTHONPATH -python c:/src/docutils/tools/rst2latex.py --documentoptions pdftex --stylesheet=docutils.sty $1 `echo $1 | sed 's/\(.*\)\..*/\1.tex/'` diff --git a/doc/scanrst.py b/doc/scanrst.py deleted file mode 100644 index 484d879..0000000 --- a/doc/scanrst.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright David Abrahams 2004. Use, modification and distribution is -# subject to 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) - -# This script accepts a list of .rst files to be processed and -# generates Makefile dependencies for .html and .rst files to stdout. -import os,sys -import re - -include = re.compile(r' *\.\. +(include|image):: +(.*)', re.MULTILINE) - -def deps(path, found): - dir = os.path.split(path)[0] - for m in re.findall(include, open(path).read()): - - dependency = os.path.normpath(os.path.join(dir,m[1])) - if dependency not in found: - found[dependency] = 1 - - if m[0] == 'include': - deps(dependency, found) - - return found - -for file in sys.argv[1:]: - found = deps(file, {}) - if found: - base = os.path.splitext(os.path.basename(file))[0] - print '%s.tex %s.html: %s' % (base, base, ' '.join(found.keys())) diff --git a/doc/sources.py b/doc/sources.py deleted file mode 100644 index 5f954a5..0000000 --- a/doc/sources.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright David Abrahams 2004. Use, modification and distribution is -# subject to 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) - -sources = [ -'counting_iterator.rst', -'facade-and-adaptor.rst', -'filter_iterator.rst', -'function_output_iterator.rst', -'index.rst', -'indirect_iterator.rst', -'pointee.rst', -'iterator_adaptor.rst', -'iterator_facade.rst', -'new-iter-concepts.rst', -'permutation_iterator.rst', -'reverse_iterator.rst', -'transform_iterator.rst', -'zip_iterator.rst', -'iterator_archetypes.rst', -'iterator_concepts.rst', -'iterator_traits.rst' - ] - diff --git a/doc/syscmd.py b/doc/syscmd.py deleted file mode 100644 index e6a8dca..0000000 --- a/doc/syscmd.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright David Abrahams 2004. Use, modification and distribution is -# subject to 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) - -import os -import sys - -def syscmd(s): - print 'executing: ', repr(s) - sys.stdout.flush() - err = os.system(s) - if err: - raise SystemError, 'command: %s returned %s' % ( - repr(s), err) diff --git a/doc/transform_iterator.html b/doc/transform_iterator.html deleted file mode 100644 index 7b8ceb1..0000000 --- a/doc/transform_iterator.html +++ /dev/null @@ -1,622 +0,0 @@ - - - - - - -Transform Iterator - - - - - - - -
-

Transform Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-11-01
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.
- - - - --- - - - -
abstract: - - -The transform iterator adapts an iterator by modifying the -operator* to apply a function object to the result of -dereferencing the iterator and returning the result.
- -
-

transform_iterator synopsis

- - - - -
-template <class UnaryFunction,
-          class Iterator,
-          class Reference = use_default,
-          class Value = use_default>
-class transform_iterator
-{
-public:
-  typedef /* see below */ value_type;
-  typedef /* see below */ reference;
-  typedef /* see below */ pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  transform_iterator();
-  transform_iterator(Iterator const& x, UnaryFunction f);
-
-  template<class F2, class I2, class R2, class V2>
-  transform_iterator(
-        transform_iterator<F2, I2, R2, V2> const& t
-      , typename enable_if_convertible<I2, Iterator>::type* = 0      // exposition only
-      , typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition only
-  );
-  UnaryFunction functor() const;
-  Iterator const& base() const;
-  reference operator*() const;
-  transform_iterator& operator++();
-  transform_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition only
-  UnaryFunction m_f;   // exposition only
-};
-
-

If Reference is use_default then the reference member of -transform_iterator is -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type. -Otherwise, reference is Reference.

-

If Value is use_default then the value_type member is -remove_cv<remove_reference<reference> >::type. Otherwise, -value_type is Value.

-

If Iterator models Readable Lvalue Iterator and if Iterator -models Random Access Traversal Iterator, then iterator_category is -convertible to random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator, then -iterator_category is convertible to -bidirectional_iterator_tag. Otherwise iterator_category is -convertible to forward_iterator_tag. If Iterator does not -model Readable Lvalue Iterator then iterator_category is -convertible to input_iterator_tag.

-
-
-

transform_iterator requirements

-

The type UnaryFunction must be Assignable, Copy Constructible, and -the expression f(*i) must be valid where f is an object of -type UnaryFunction, i is an object of type Iterator, and -where the type of f(*i) must be -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type.

-

The argument Iterator shall model Readable Iterator.

-
-
-

transform_iterator models

-

The resulting transform_iterator models the most refined of the -following that is also modeled by Iterator.

-
-
    -
  • Writable Lvalue Iterator if transform_iterator::reference is a non-const reference.
  • -
  • Readable Lvalue Iterator if transform_iterator::reference is a const reference.
  • -
  • Readable Iterator otherwise.
  • -
-
-

The transform_iterator models the most refined standard traversal -concept that is modeled by the Iterator argument.

-

If transform_iterator is a model of Readable Lvalue Iterator then -it models the following original iterator concepts depending on what -the Iterator argument models.

- ---- - - - - - - - - - - - - - - - - - - - -
If Iterator modelsthen transform_iterator models
Single Pass IteratorInput Iterator
Forward Traversal IteratorForward Iterator
Bidirectional Traversal IteratorBidirectional Iterator
Random Access Traversal IteratorRandom Access Iterator
-

If transform_iterator models Writable Lvalue Iterator then it is a -mutable iterator (as defined in the old iterator requirements).

-

transform_iterator<F1, X, R1, V1> is interoperable with -transform_iterator<F2, Y, R2, V2> if and only if X is -interoperable with Y.

-
-
-

transform_iterator operations

-

In addition to the operations required by the concepts modeled by -transform_iterator, transform_iterator provides the following -operations.

-

transform_iterator();

- --- - - - -
Returns:An instance of transform_iterator with m_f -and m_iterator default constructed.
-

transform_iterator(Iterator const& x, UnaryFunction f);

- --- - - - -
Returns:An instance of transform_iterator with m_f -initialized to f and m_iterator initialized to x.
-
-template<class F2, class I2, class R2, class V2>
-transform_iterator(
-      transform_iterator<F2, I2, R2, V2> const& t
-    , typename enable_if_convertible<I2, Iterator>::type* = 0      // exposition only
-    , typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition only
-);
-
- --- - - - - - -
Returns:An instance of transform_iterator with m_f -initialized to t.functor() and m_iterator initialized to -t.base().
Requires:OtherIterator is implicitly convertible to Iterator.
-

UnaryFunction functor() const;

- --- - - - -
Returns:m_f
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:m_f(*m_iterator)
-

transform_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

transform_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
- - - -
-template <class UnaryFunction, class Iterator>
-transform_iterator<UnaryFunction, Iterator>
-make_transform_iterator(Iterator it, UnaryFunction fun);
-
- --- - - - -
Returns:An instance of transform_iterator<UnaryFunction, Iterator> with m_f -initialized to f and m_iterator initialized to x.
-
-template <class UnaryFunction, class Iterator>
-transform_iterator<UnaryFunction, Iterator>
-make_transform_iterator(Iterator it);
-
- --- - - - -
Returns:An instance of transform_iterator<UnaryFunction, Iterator> with m_f -default constructed and m_iterator initialized to x.
- - - -
-
-

Example

-

This is a simple example of using the transform_iterators class to -generate iterators that multiply (or add to) the value returned by -dereferencing the iterator. It would be cooler to use lambda library -in this example.

-
-int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
-const int N = sizeof(x)/sizeof(int);
-
-typedef boost::binder1st< std::multiplies<int> > Function;
-typedef boost::transform_iterator<Function, int*> doubling_iterator;
-
-doubling_iterator i(x, boost::bind1st(std::multiplies<int>(), 2)),
-  i_end(x + N, boost::bind1st(std::multiplies<int>(), 2));
-
-std::cout << "multiplying the array by 2:" << std::endl;
-while (i != i_end)
-  std::cout << *i++ << " ";
-std::cout << std::endl;
-
-std::cout << "adding 4 to each element in the array:" << std::endl;
-std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus<int>(), 4)),
-          boost::make_transform_iterator(x + N, boost::bind1st(std::plus<int>(), 4)),
-          std::ostream_iterator<int>(std::cout, " "));
-std::cout << std::endl;
-
-

The output is:

-
-multiplying the array by 2:
-2 4 6 8 10 12 14 16
-adding 4 to each element in the array:
-5 6 7 8 9 10 11 12
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/transform_iterator.pdf b/doc/transform_iterator.pdf deleted file mode 100755 index 2af10ab..0000000 Binary files a/doc/transform_iterator.pdf and /dev/null differ diff --git a/doc/transform_iterator.rst b/doc/transform_iterator.rst deleted file mode 100644 index 4f81cca..0000000 --- a/doc/transform_iterator.rst +++ /dev/null @@ -1,32 +0,0 @@ -.. 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) - -++++++++++++++++++++ - Transform Iterator -++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: transform_iterator_abstract.rst - -.. contents:: Table of Contents - -``transform_iterator`` synopsis -............................... - -.. include:: transform_iterator_ref.rst -.. include:: make_transform_iterator.rst -.. include:: transform_iterator_eg.rst diff --git a/doc/transform_iterator_abstract.rst b/doc/transform_iterator_abstract.rst deleted file mode 100644 index 5fdcf53..0000000 --- a/doc/transform_iterator_abstract.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. 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) - -The transform iterator adapts an iterator by modifying the -``operator*`` to apply a function object to the result of -dereferencing the iterator and returning the result. diff --git a/doc/transform_iterator_eg.rst b/doc/transform_iterator_eg.rst deleted file mode 100755 index 1406d2b..0000000 --- a/doc/transform_iterator_eg.rst +++ /dev/null @@ -1,46 +0,0 @@ -.. 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) - -Example -....... - -This is a simple example of using the transform_iterators class to -generate iterators that multiply (or add to) the value returned by -dereferencing the iterator. It would be cooler to use lambda library -in this example. - -:: - - int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; - const int N = sizeof(x)/sizeof(int); - - typedef boost::binder1st< std::multiplies > Function; - typedef boost::transform_iterator doubling_iterator; - - doubling_iterator i(x, boost::bind1st(std::multiplies(), 2)), - i_end(x + N, boost::bind1st(std::multiplies(), 2)); - - std::cout << "multiplying the array by 2:" << std::endl; - while (i != i_end) - std::cout << *i++ << " "; - std::cout << std::endl; - - std::cout << "adding 4 to each element in the array:" << std::endl; - std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus(), 4)), - boost::make_transform_iterator(x + N, boost::bind1st(std::plus(), 4)), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - -The output is:: - - multiplying the array by 2: - 2 4 6 8 10 12 14 16 - adding 4 to each element in the array: - 5 6 7 8 9 10 11 12 - - -The source code for this example can be found `here`__. - -__ ../example/transform_iterator_example.cpp diff --git a/doc/transform_iterator_ref.rst b/doc/transform_iterator_ref.rst deleted file mode 100644 index 74347a0..0000000 --- a/doc/transform_iterator_ref.rst +++ /dev/null @@ -1,175 +0,0 @@ -.. 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) - -.. Version 1.3 of this document was accepted for TR1 - -:: - - template - class transform_iterator - { - public: - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - transform_iterator(); - transform_iterator(Iterator const& x, UnaryFunction f); - - template - transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition only - , typename enable_if_convertible::type* = 0 // exposition only - ); - UnaryFunction functor() const; - Iterator const& base() const; - reference operator*() const; - transform_iterator& operator++(); - transform_iterator& operator--(); - private: - Iterator m_iterator; // exposition only - UnaryFunction m_f; // exposition only - }; - - -If ``Reference`` is ``use_default`` then the ``reference`` member of -``transform_iterator`` is -``result_of::reference)>::type``. -Otherwise, ``reference`` is ``Reference``. - -If ``Value`` is ``use_default`` then the ``value_type`` member is -``remove_cv >::type``. Otherwise, -``value_type`` is ``Value``. - - -If ``Iterator`` models Readable Lvalue Iterator and if ``Iterator`` -models Random Access Traversal Iterator, then ``iterator_category`` is -convertible to ``random_access_iterator_tag``. Otherwise, if -``Iterator`` models Bidirectional Traversal Iterator, then -``iterator_category`` is convertible to -``bidirectional_iterator_tag``. Otherwise ``iterator_category`` is -convertible to ``forward_iterator_tag``. If ``Iterator`` does not -model Readable Lvalue Iterator then ``iterator_category`` is -convertible to ``input_iterator_tag``. - - -``transform_iterator`` requirements -................................... - -The type ``UnaryFunction`` must be Assignable, Copy Constructible, and -the expression ``f(*i)`` must be valid where ``f`` is an object of -type ``UnaryFunction``, ``i`` is an object of type ``Iterator``, and -where the type of ``f(*i)`` must be -``result_of::reference)>::type``. - -The argument ``Iterator`` shall model Readable Iterator. - - -``transform_iterator`` models -............................. - -The resulting ``transform_iterator`` models the most refined of the -following that is also modeled by ``Iterator``. - - * Writable Lvalue Iterator if ``transform_iterator::reference`` is a non-const reference. - - * Readable Lvalue Iterator if ``transform_iterator::reference`` is a const reference. - - * Readable Iterator otherwise. - -The ``transform_iterator`` models the most refined standard traversal -concept that is modeled by the ``Iterator`` argument. - -If ``transform_iterator`` is a model of Readable Lvalue Iterator then -it models the following original iterator concepts depending on what -the ``Iterator`` argument models. - -+-----------------------------------+---------------------------------------+ -| If ``Iterator`` models | then ``transform_iterator`` models | -+===================================+=======================================+ -| Single Pass Iterator | Input Iterator | -+-----------------------------------+---------------------------------------+ -| Forward Traversal Iterator | Forward Iterator | -+-----------------------------------+---------------------------------------+ -| Bidirectional Traversal Iterator | Bidirectional Iterator | -+-----------------------------------+---------------------------------------+ -| Random Access Traversal Iterator | Random Access Iterator | -+-----------------------------------+---------------------------------------+ - -If ``transform_iterator`` models Writable Lvalue Iterator then it is a -mutable iterator (as defined in the old iterator requirements). - -``transform_iterator`` is interoperable with -``transform_iterator`` if and only if ``X`` is -interoperable with ``Y``. - - - -``transform_iterator`` operations -................................. - -In addition to the operations required by the concepts modeled by -``transform_iterator``, ``transform_iterator`` provides the following -operations. - - -``transform_iterator();`` - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - and ``m_iterator`` default constructed. - - -``transform_iterator(Iterator const& x, UnaryFunction f);`` - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - initialized to ``f`` and ``m_iterator`` initialized to ``x``. - - -:: - - template - transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition only - , typename enable_if_convertible::type* = 0 // exposition only - ); - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - initialized to ``t.functor()`` and ``m_iterator`` initialized to - ``t.base()``. -:Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. - - -``UnaryFunction functor() const;`` - -:Returns: ``m_f`` - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - -``reference operator*() const;`` - -:Returns: ``m_f(*m_iterator)`` - - -``transform_iterator& operator++();`` - -:Effects: ``++m_iterator`` -:Returns: ``*this`` - - -``transform_iterator& operator--();`` - -:Effects: ``--m_iterator`` -:Returns: ``*this`` - diff --git a/doc/traversal.png b/doc/traversal.png deleted file mode 100644 index a9bbe98..0000000 Binary files a/doc/traversal.png and /dev/null differ diff --git a/doc/zip_iterator.html b/doc/zip_iterator.html deleted file mode 100755 index 559f262..0000000 --- a/doc/zip_iterator.html +++ /dev/null @@ -1,643 +0,0 @@ - - - - - - -Zip Iterator - - - - - - - -
-

Zip Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Thomas Becker
Contact:dave@boost-consulting.com, thomas@styleadvisor.com
Organization:Boost Consulting, Zephyr Associates, Inc.
Date:2004-11-01
Copyright:Copyright David Abrahams and Thomas Becker 2003.
- - - - --- - - - -
abstract: - - -The zip iterator provides the ability to parallel-iterate -over several controlled sequences simultaneously. A zip -iterator is constructed from a tuple of iterators. Moving -the zip iterator moves all the iterators in parallel. -Dereferencing the zip iterator returns a tuple that contains -the results of dereferencing the individual iterators.
- -
-

zip_iterator synopsis

- - - -
-template<typename IteratorTuple>
-class zip_iterator
-{
-
-public:
-  typedef /* see below */ reference;
-  typedef reference value_type;
-  typedef value_type* pointer;
-  typedef /* see below */ difference_type;
-  typedef /* see below */ iterator_category;
-
-  zip_iterator();
-  zip_iterator(IteratorTuple iterator_tuple);
-
-  template<typename OtherIteratorTuple>
-  zip_iterator(
-        const zip_iterator<OtherIteratorTuple>& other
-      , typename enable_if_convertible<
-              OtherIteratorTuple
-            , IteratorTuple>::type* = 0     // exposition only
-  );
-
-  const IteratorTuple& get_iterator_tuple() const;
-
-private:
-  IteratorTuple m_iterator_tuple;     // exposition only
-};
-
-template<typename IteratorTuple>
-zip_iterator<IteratorTuple>
-make_zip_iterator(IteratorTuple t);
-
-

The reference member of zip_iterator is the type of the tuple -made of the reference types of the iterator types in the IteratorTuple -argument.

-

The difference_type member of zip_iterator is the difference_type -of the first of the iterator types in the IteratorTuple argument.

-

The iterator_category member of zip_iterator is convertible to the -minimum of the traversal categories of the iterator types in the IteratorTuple -argument. For example, if the zip_iterator holds only vector -iterators, then iterator_category is convertible to -boost::random_access_traversal_tag. If you add a list iterator, then -iterator_category will be convertible to boost::bidirectional_traversal_tag, -but no longer to boost::random_access_traversal_tag.

-
-
-

zip_iterator requirements

-

All iterator types in the argument IteratorTuple shall model Readable Iterator.

-
-
-

zip_iterator models

-

The resulting zip_iterator models Readable Iterator.

-

The fact that the zip_iterator models only Readable Iterator does not -prevent you from modifying the values that the individual iterators point -to. The tuple returned by the zip_iterator's operator* is a tuple -constructed from the reference types of the individual iterators, not -their value types. For example, if zip_it is a zip_iterator whose -first member iterator is an std::vector<double>::iterator, then the -following line will modify the value which the first member iterator of -zip_it currently points to:

-
-zip_it->get<0>() = 42.0;
-
-

Consider the set of standard traversal concepts obtained by taking -the most refined standard traversal concept modeled by each individual -iterator type in the IteratorTuple argument.The zip_iterator -models the least refined standard traversal concept in this set.

-

zip_iterator<IteratorTuple1> is interoperable with -zip_iterator<IteratorTuple2> if and only if IteratorTuple1 -is interoperable with IteratorTuple2.

-
-
-

zip_iterator operations

-

In addition to the operations required by the concepts modeled by -zip_iterator, zip_iterator provides the following -operations.

-

zip_iterator();

- --- - - - -
Returns:An instance of zip_iterator with m_iterator_tuple -default constructed.
-

zip_iterator(IteratorTuple iterator_tuple);

- --- - - - -
Returns:An instance of zip_iterator with m_iterator_tuple -initialized to iterator_tuple.
-
-template<typename OtherIteratorTuple>
-zip_iterator(
-      const zip_iterator<OtherIteratorTuple>& other
-    , typename enable_if_convertible<
-            OtherIteratorTuple
-          , IteratorTuple>::type* = 0     // exposition only
-);
-
- --- - - - - - -
Returns:An instance of zip_iterator that is a copy of other.
Requires:OtherIteratorTuple is implicitly convertible to IteratorTuple.
-

const IteratorTuple& get_iterator_tuple() const;

- --- - - - -
Returns:m_iterator_tuple
-

reference operator*() const;

- --- - - - -
Returns:A tuple consisting of the results of dereferencing all iterators in -m_iterator_tuple.
-

zip_iterator& operator++();

- --- - - - - - -
Effects:Increments each iterator in m_iterator_tuple.
Returns:*this
-

zip_iterator& operator--();

- --- - - - - - -
Effects:Decrements each iterator in m_iterator_tuple.
Returns:*this
-
-template<typename IteratorTuple>
-zip_iterator<IteratorTuple>
-make_zip_iterator(IteratorTuple t);
-
- --- - - - -
Returns:An instance of zip_iterator<IteratorTuple> with m_iterator_tuple -initialized to t.
- - - -
-template<typename IteratorTuple>
-zip_iterator<IteratorTuple>
-make_zip_iterator(IteratorTuple t);
-
- --- - - - -
Returns:An instance of zip_iterator<IteratorTuple> with m_iterator_tuple -initialized to t.
- - - -
-
-

Examples

-

There are two main types of applications of the zip_iterator. The first -one concerns runtime efficiency: If one has several controlled sequences -of the same length that must be somehow processed, e.g., with the -for_each algorithm, then it is more efficient to perform just -one parallel-iteration rather than several individual iterations. For an -example, assume that vect_of_doubles and vect_of_ints -are two vectors of equal length containing doubles and ints, respectively, -and consider the following two iterations:

-
-std::vector<double>::const_iterator beg1 = vect_of_doubles.begin();
-std::vector<double>::const_iterator end1 = vect_of_doubles.end();
-std::vector<int>::const_iterator beg2 = vect_of_ints.begin();
-std::vector<int>::const_iterator end2 = vect_of_ints.end();
-
-std::for_each(beg1, end1, func_0());
-std::for_each(beg2, end2, func_1());
-
-

These two iterations can now be replaced with a single one as follows:

-
-std::for_each(
-  boost::make_zip_iterator(
-    boost::make_tuple(beg1, beg2)
-    ),
-  boost::make_zip_iterator(
-    boost::make_tuple(end1, end2)
-    ),
-  zip_func()
-  );
-
-

A non-generic implementation of zip_func could look as follows:

-
-struct zip_func :
-  public std::unary_function<const boost::tuple<const double&, const int&>&, void>
-{
-  void operator()(const boost::tuple<const double&, const int&>& t) const
-  {
-    m_f0(t.get<0>());
-    m_f1(t.get<1>());
-  }
-
-private:
-  func_0 m_f0;
-  func_1 m_f1;
-};
-
-

The second important application of the zip_iterator is as a building block -to make combining iterators. A combining iterator is an iterator -that parallel-iterates over several controlled sequences and, upon -dereferencing, returns the result of applying a functor to the values of the -sequences at the respective positions. This can now be achieved by using the -zip_iterator in conjunction with the transform_iterator.

-

Suppose, for example, that you have two vectors of doubles, say -vect_1 and vect_2, and you need to expose to a client -a controlled sequence containing the products of the elements of -vect_1 and vect_2. Rather than placing these products -in a third vector, you can use a combining iterator that calculates the -products on the fly. Let us assume that tuple_multiplies is a -functor that works like std::multiplies, except that it takes -its two arguments packaged in a tuple. Then the two iterators -it_begin and it_end defined below delimit a controlled -sequence containing the products of the elements of vect_1 and -vect_2:

-
-typedef boost::tuple<
-  std::vector<double>::const_iterator,
-  std::vector<double>::const_iterator
-  > the_iterator_tuple;
-
-typedef boost::zip_iterator<
-  the_iterator_tuple
-  > the_zip_iterator;
-
-typedef boost::transform_iterator<
-  tuple_multiplies<double>,
-  the_zip_iterator
-  > the_transform_iterator;
-
-the_transform_iterator it_begin(
-  the_zip_iterator(
-    the_iterator_tuple(
-      vect_1.begin(),
-      vect_2.begin()
-      )
-    ),
-  tuple_multiplies<double>()
-  );
-
-the_transform_iterator it_end(
-  the_zip_iterator(
-    the_iterator_tuple(
-      vect_1.end(),
-      vect_2.end()
-      )
-    ),
-  tuple_multiplies<double>()
-  );
-
-
-
- - diff --git a/doc/zip_iterator.pdf b/doc/zip_iterator.pdf deleted file mode 100755 index c5a6f21..0000000 Binary files a/doc/zip_iterator.pdf and /dev/null differ diff --git a/doc/zip_iterator.rst b/doc/zip_iterator.rst deleted file mode 100755 index 4e360c3..0000000 --- a/doc/zip_iterator.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. 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) - -+++++++++++++ - Zip Iterator -+++++++++++++ - -:Author: David Abrahams, Thomas Becker -:Contact: dave@boost-consulting.com, thomas@styleadvisor.com -:organization: `Boost Consulting`_, `Zephyr Associates, Inc.`_ -:date: $Date$ -:copyright: Copyright David Abrahams and Thomas Becker 2003. - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:abstract: - - .. include:: zip_iterator_abstract.rst - -.. contents:: Table of Contents - -``zip_iterator`` synopsis -............................... - -.. include:: zip_iterator_ref.rst -.. include:: make_zip_iterator.rst -.. include:: zip_iterator_eg.rst diff --git a/doc/zip_iterator_abstract.rst b/doc/zip_iterator_abstract.rst deleted file mode 100755 index 2f4aecf..0000000 --- a/doc/zip_iterator_abstract.rst +++ /dev/null @@ -1,10 +0,0 @@ -.. 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) - -The zip iterator provides the ability to parallel-iterate -over several controlled sequences simultaneously. A zip -iterator is constructed from a tuple of iterators. Moving -the zip iterator moves all the iterators in parallel. -Dereferencing the zip iterator returns a tuple that contains -the results of dereferencing the individual iterators. diff --git a/doc/zip_iterator_eg.rst b/doc/zip_iterator_eg.rst deleted file mode 100755 index e999f15..0000000 --- a/doc/zip_iterator_eg.rst +++ /dev/null @@ -1,116 +0,0 @@ -.. 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) - -Examples -........ - -There are two main types of applications of the ``zip_iterator``. The first -one concerns runtime efficiency: If one has several controlled sequences -of the same length that must be somehow processed, e.g., with the -``for_each`` algorithm, then it is more efficient to perform just -one parallel-iteration rather than several individual iterations. For an -example, assume that ``vect_of_doubles`` and ``vect_of_ints`` -are two vectors of equal length containing doubles and ints, respectively, -and consider the following two iterations: - -:: - - - std::vector::const_iterator beg1 = vect_of_doubles.begin(); - std::vector::const_iterator end1 = vect_of_doubles.end(); - std::vector::const_iterator beg2 = vect_of_ints.begin(); - std::vector::const_iterator end2 = vect_of_ints.end(); - - std::for_each(beg1, end1, func_0()); - std::for_each(beg2, end2, func_1()); - -These two iterations can now be replaced with a single one as follows: - -:: - - - std::for_each( - boost::make_zip_iterator( - boost::make_tuple(beg1, beg2) - ), - boost::make_zip_iterator( - boost::make_tuple(end1, end2) - ), - zip_func() - ); - -A non-generic implementation of ``zip_func`` could look as follows: - -:: - - - struct zip_func : - public std::unary_function&, void> - { - void operator()(const boost::tuple& t) const - { - m_f0(t.get<0>()); - m_f1(t.get<1>()); - } - - private: - func_0 m_f0; - func_1 m_f1; - }; - -The second important application of the ``zip_iterator`` is as a building block -to make combining iterators. A combining iterator is an iterator -that parallel-iterates over several controlled sequences and, upon -dereferencing, returns the result of applying a functor to the values of the -sequences at the respective positions. This can now be achieved by using the -``zip_iterator`` in conjunction with the ``transform_iterator``. - -Suppose, for example, that you have two vectors of doubles, say -``vect_1`` and ``vect_2``, and you need to expose to a client -a controlled sequence containing the products of the elements of -``vect_1`` and ``vect_2``. Rather than placing these products -in a third vector, you can use a combining iterator that calculates the -products on the fly. Let us assume that ``tuple_multiplies`` is a -functor that works like ``std::multiplies``, except that it takes -its two arguments packaged in a tuple. Then the two iterators -``it_begin`` and ``it_end`` defined below delimit a controlled -sequence containing the products of the elements of ``vect_1`` and -``vect_2``: - -:: - - - typedef boost::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > the_iterator_tuple; - - typedef boost::zip_iterator< - the_iterator_tuple - > the_zip_iterator; - - typedef boost::transform_iterator< - tuple_multiplies, - the_zip_iterator - > the_transform_iterator; - - the_transform_iterator it_begin( - the_zip_iterator( - the_iterator_tuple( - vect_1.begin(), - vect_2.begin() - ) - ), - tuple_multiplies() - ); - - the_transform_iterator it_end( - the_zip_iterator( - the_iterator_tuple( - vect_1.end(), - vect_2.end() - ) - ), - tuple_multiplies() - ); diff --git a/doc/zip_iterator_ref.rst b/doc/zip_iterator_ref.rst deleted file mode 100755 index f81ccd2..0000000 --- a/doc/zip_iterator_ref.rst +++ /dev/null @@ -1,155 +0,0 @@ -.. 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) - -:: - - template - class zip_iterator - { - - public: - typedef /* see below */ reference; - typedef reference value_type; - typedef value_type* pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - - zip_iterator(); - zip_iterator(IteratorTuple iterator_tuple); - - template - zip_iterator( - const zip_iterator& other - , typename enable_if_convertible< - OtherIteratorTuple - , IteratorTuple>::type* = 0 // exposition only - ); - - const IteratorTuple& get_iterator_tuple() const; - - private: - IteratorTuple m_iterator_tuple; // exposition only - }; - - template - zip_iterator - make_zip_iterator(IteratorTuple t); - - -The ``reference`` member of ``zip_iterator`` is the type of the tuple -made of the reference types of the iterator types in the ``IteratorTuple`` -argument. - -The ``difference_type`` member of ``zip_iterator`` is the ``difference_type`` -of the first of the iterator types in the ``IteratorTuple`` argument. - -The ``iterator_category`` member of ``zip_iterator`` is convertible to the -minimum of the traversal categories of the iterator types in the ``IteratorTuple`` -argument. For example, if the ``zip_iterator`` holds only vector -iterators, then ``iterator_category`` is convertible to -``boost::random_access_traversal_tag``. If you add a list iterator, then -``iterator_category`` will be convertible to ``boost::bidirectional_traversal_tag``, -but no longer to ``boost::random_access_traversal_tag``. - - -``zip_iterator`` requirements -................................... - -All iterator types in the argument ``IteratorTuple`` shall model Readable Iterator. - - -``zip_iterator`` models -............................. - -The resulting ``zip_iterator`` models Readable Iterator. - -The fact that the ``zip_iterator`` models only Readable Iterator does not -prevent you from modifying the values that the individual iterators point -to. The tuple returned by the ``zip_iterator``'s ``operator*`` is a tuple -constructed from the reference types of the individual iterators, not -their value types. For example, if ``zip_it`` is a ``zip_iterator`` whose -first member iterator is an ``std::vector::iterator``, then the -following line will modify the value which the first member iterator of -``zip_it`` currently points to: - -:: - - zip_it->get<0>() = 42.0; - - -Consider the set of standard traversal concepts obtained by taking -the most refined standard traversal concept modeled by each individual -iterator type in the ``IteratorTuple`` argument.The ``zip_iterator`` -models the least refined standard traversal concept in this set. - -``zip_iterator`` is interoperable with -``zip_iterator`` if and only if ``IteratorTuple1`` -is interoperable with ``IteratorTuple2``. - - - -``zip_iterator`` operations -................................. - -In addition to the operations required by the concepts modeled by -``zip_iterator``, ``zip_iterator`` provides the following -operations. - - -``zip_iterator();`` - -:Returns: An instance of ``zip_iterator`` with ``m_iterator_tuple`` - default constructed. - - -``zip_iterator(IteratorTuple iterator_tuple);`` - -:Returns: An instance of ``zip_iterator`` with ``m_iterator_tuple`` - initialized to ``iterator_tuple``. - - -:: - - template - zip_iterator( - const zip_iterator& other - , typename enable_if_convertible< - OtherIteratorTuple - , IteratorTuple>::type* = 0 // exposition only - ); - -:Returns: An instance of ``zip_iterator`` that is a copy of ``other``. -:Requires: ``OtherIteratorTuple`` is implicitly convertible to ``IteratorTuple``. - - -``const IteratorTuple& get_iterator_tuple() const;`` - -:Returns: ``m_iterator_tuple`` - - -``reference operator*() const;`` - -:Returns: A tuple consisting of the results of dereferencing all iterators in - ``m_iterator_tuple``. - - -``zip_iterator& operator++();`` - -:Effects: Increments each iterator in ``m_iterator_tuple``. -:Returns: ``*this`` - - -``zip_iterator& operator--();`` - -:Effects: Decrements each iterator in ``m_iterator_tuple``. -:Returns: ``*this`` - -:: - - template - zip_iterator - make_zip_iterator(IteratorTuple t); - -:Returns: An instance of ``zip_iterator`` with ``m_iterator_tuple`` - initialized to ``t``. diff --git a/example/counting_iterator_example.cpp b/example/counting_iterator_example.cpp deleted file mode 100644 index c7d8add..0000000 --- a/example/counting_iterator_example.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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) - - -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int, char*[]) -{ - // Example of using counting_iterator - std::cout << "counting from 0 to 4:" << std::endl; - boost::counting_iterator first(0), last(4); - std::copy(first, last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example of using counting iterator to create an array of pointers. - int N = 7; - std::vector numbers; - typedef std::vector::iterator n_iter; - // Fill "numbers" array with [0,N) - std::copy( - boost::counting_iterator(0) - , boost::counting_iterator(N) - , std::back_inserter(numbers)); - - std::vector::iterator> pointers; - - // Use counting iterator to fill in the array of pointers. - // causes an ICE with MSVC6 - std::copy(boost::make_counting_iterator(numbers.begin()), - boost::make_counting_iterator(numbers.end()), - std::back_inserter(pointers)); - - // Use indirect iterator to print out numbers by accessing - // them through the array of pointers. - std::cout << "indirectly printing out the numbers from 0 to " - << N << std::endl; - std::copy(boost::make_indirect_iterator(pointers.begin()), - boost::make_indirect_iterator(pointers.end()), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - return boost::exit_success; -} diff --git a/example/filter_iterator_example.cpp b/example/filter_iterator_example.cpp deleted file mode 100644 index 8880c8d..0000000 --- a/example/filter_iterator_example.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// (C) Copyright Jeremy Siek 1999-2004. -// 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) - -#include -#include -#include -#include -#include -#include // for exit_success - -struct is_positive_number { - bool operator()(int x) { return 0 < x; } -}; - -int main() -{ - int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 }; - const int N = sizeof(numbers_)/sizeof(int); - - typedef int* base_iterator; - base_iterator numbers(numbers_); - - // Example using make_filter_iterator() - std::copy(boost::make_filter_iterator(numbers, numbers + N), - boost::make_filter_iterator(numbers + N, numbers + N), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example using filter_iterator - typedef boost::filter_iterator - FilterIter; - - is_positive_number predicate; - FilterIter filter_iter_first(predicate, numbers, numbers + N); - FilterIter filter_iter_last(predicate, numbers + N, numbers + N); - - std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Another example using make_filter_iterator() - std::copy( - boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers, numbers + N) - - , boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers + N, numbers + N) - - , std::ostream_iterator(std::cout, " ") - ); - - std::cout << std::endl; - - return boost::exit_success; -} diff --git a/example/func_output_iter_example.cpp b/example/func_output_iter_example.cpp deleted file mode 100644 index 9c06319..0000000 --- a/example/func_output_iter_example.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// (C) Copyright Jeremy Siek 2001-2004. -// 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) - -// Revision History: - -// 27 Feb 2001 Jeremy Siek -// Initial checkin. - -#include -#include -#include - -#include - -struct string_appender -{ - string_appender(std::string& s) - : m_str(&s) - {} - - void operator()(const std::string& x) const - { - *m_str += x; - } - - std::string* m_str; -}; - -int main(int, char*[]) -{ - std::vector x; - x.push_back("hello"); - x.push_back(" "); - x.push_back("world"); - x.push_back("!"); - - std::string s = ""; - std::copy(x.begin(), x.end(), - boost::make_function_output_iterator(string_appender(s))); - - std::cout << s << std::endl; - - return 0; -} diff --git a/example/indirect_iterator_example.cpp b/example/indirect_iterator_example.cpp deleted file mode 100644 index abbf46c..0000000 --- a/example/indirect_iterator_example.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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) - -#include -#include -#include -#include -#include -#include -#include - -int main(int, char*[]) -{ - char characters[] = "abcdefg"; - const int N = sizeof(characters)/sizeof(char) - 1; // -1 since characters has a null char - char* pointers_to_chars[N]; // at the end. - for (int i = 0; i < N; ++i) - pointers_to_chars[i] = &characters[i]; - - // Example of using indirect_iterator - - boost::indirect_iterator - indirect_first(pointers_to_chars), indirect_last(pointers_to_chars + N); - - std::copy(indirect_first, indirect_last, std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of making mutable and constant indirect iterators - - char mutable_characters[N]; - char* pointers_to_mutable_chars[N]; - for (int j = 0; j < N; ++j) - pointers_to_mutable_chars[j] = &mutable_characters[j]; - - boost::indirect_iterator mutable_indirect_first(pointers_to_mutable_chars), - mutable_indirect_last(pointers_to_mutable_chars + N); - boost::indirect_iterator const_indirect_first(pointers_to_chars), - const_indirect_last(pointers_to_chars + N); - - std::transform(const_indirect_first, const_indirect_last, - mutable_indirect_first, std::bind1st(std::plus(), 1)); - - std::copy(mutable_indirect_first, mutable_indirect_last, - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of using make_indirect_iterator() - - std::copy(boost::make_indirect_iterator(pointers_to_chars), - boost::make_indirect_iterator(pointers_to_chars + N), - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - return 0; -} diff --git a/example/node.hpp b/example/node.hpp deleted file mode 100755 index c3ed315..0000000 --- a/example/node.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) -#ifndef NODE_DWA2004110_HPP -# define NODE_DWA2004110_HPP - -# include - -// Polymorphic list node base class - -struct node_base -{ - node_base() : m_next(0) {} - - virtual ~node_base() - { - delete m_next; - } - - node_base* next() const - { - return m_next; - } - - virtual void print(std::ostream& s) const = 0; - virtual void double_me() = 0; - - void append(node_base* p) - { - if (m_next) - m_next->append(p); - else - m_next = p; - } - - private: - node_base* m_next; -}; - -inline std::ostream& operator<<(std::ostream& s, node_base const& n) -{ - n.print(s); - return s; -} - -template -struct node : node_base -{ - node(T x) - : m_value(x) - {} - - void print(std::ostream& s) const { s << this->m_value; } - void double_me() { m_value += m_value; } - - private: - T m_value; -}; - -#endif // NODE_DWA2004110_HPP diff --git a/example/node_iterator1.cpp b/example/node_iterator1.cpp deleted file mode 100755 index 6411b03..0000000 --- a/example/node_iterator1.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) - -#include "node_iterator1.hpp" -#include -#include -#include -#include -#include - -int main() -{ - std::auto_ptr > nodes(new node(42)); - nodes->append(new node(" is greater than ")); - nodes->append(new node(13)); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, " ") - ); - std::cout << std::endl; - - std::for_each( - node_iterator(nodes.get()), node_iterator() - , std::mem_fun_ref(&node_base::double_me) - ); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, "/") - ); - std::cout << std::endl; -} diff --git a/example/node_iterator1.hpp b/example/node_iterator1.hpp deleted file mode 100755 index 5e068b4..0000000 --- a/example/node_iterator1.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) -#ifndef NODE_ITERATOR1_DWA2004110_HPP -# define NODE_ITERATOR1_DWA2004110_HPP - -# include "node.hpp" -# include - -class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > -{ - public: - node_iterator() - : m_node(0) - {} - - explicit node_iterator(node_base* p) - : m_node(p) - {} - - private: - friend class boost::iterator_core_access; - - void increment() - { m_node = m_node->next(); } - - bool equal(node_iterator const& other) const - { return this->m_node == other.m_node; } - - node_base& dereference() const - { return *m_node; } - - node_base* m_node; -}; - - -#endif // NODE_ITERATOR1_DWA2004110_HPP diff --git a/example/node_iterator2.cpp b/example/node_iterator2.cpp deleted file mode 100755 index 62211b2..0000000 --- a/example/node_iterator2.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) - -#include "node_iterator2.hpp" -#include -#include -#include -#include -#include -#include - -int main() -{ - std::auto_ptr > nodes(new node(42)); - nodes->append(new node(" is greater than ")); - nodes->append(new node(13)); - - // Check interoperability - assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get())); - assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get())); - - assert(node_iterator(nodes.get()) != node_const_iterator()); - assert(node_const_iterator(nodes.get()) != node_iterator()); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, " ") - ); - std::cout << std::endl; - - std::for_each( - node_iterator(nodes.get()), node_iterator() - , boost::mem_fn(&node_base::double_me) - ); - - std::copy( - node_const_iterator(nodes.get()), node_const_iterator() - , std::ostream_iterator(std::cout, "/") - ); - std::cout << std::endl; - return 0; -} diff --git a/example/node_iterator2.hpp b/example/node_iterator2.hpp deleted file mode 100755 index 6aa0a4c..0000000 --- a/example/node_iterator2.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) -#ifndef NODE_ITERATOR2_DWA2004110_HPP -# define NODE_ITERATOR2_DWA2004110_HPP - -# include "node.hpp" -# include - -# ifndef BOOST_NO_SFINAE -# include -# include -# endif - -template -class node_iter - : public boost::iterator_facade< - node_iter - , Value - , boost::forward_traversal_tag - > -{ - private: - struct enabler {}; // a private type avoids misuse - - public: - node_iter() - : m_node(0) {} - - explicit node_iter(Value* p) - : m_node(p) {} - - template - node_iter( - node_iter const& other -# ifndef BOOST_NO_SFINAE - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() -# endif - ) - : m_node(other.m_node) {} - - -# if !BOOST_WORKAROUND(__GNUC__, == 2) - private: // GCC2 can't grant friendship to template member functions - friend class boost::iterator_core_access; -# endif - - template - bool equal(node_iter const& other) const - { - return this->m_node == other.m_node; - } - - void increment() { m_node = m_node->next(); } - - Value& dereference() const { return *m_node; } - -# ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS - public: -# else - private: - template friend class node_iter; -# endif - Value* m_node; -}; - -typedef node_iter node_iterator; -typedef node_iter node_const_iterator; - -#endif // NODE_ITERATOR2_DWA2004110_HPP diff --git a/example/node_iterator3.cpp b/example/node_iterator3.cpp deleted file mode 100755 index 331cc93..0000000 --- a/example/node_iterator3.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) - -#include "node_iterator3.hpp" -#include -#include -#include -#include -#include -#include - -int main() -{ - std::auto_ptr > nodes(new node(42)); - nodes->append(new node(" is greater than ")); - nodes->append(new node(13)); - - // Check interoperability - assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get())); - assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get())); - - assert(node_iterator(nodes.get()) != node_const_iterator()); - assert(node_const_iterator(nodes.get()) != node_iterator()); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, " ") - ); - std::cout << std::endl; - - std::for_each( - node_iterator(nodes.get()), node_iterator() - , boost::mem_fn(&node_base::double_me) - ); - - std::copy( - node_const_iterator(nodes.get()), node_const_iterator() - , std::ostream_iterator(std::cout, "/") - ); - std::cout << std::endl; - return 0; -} diff --git a/example/node_iterator3.hpp b/example/node_iterator3.hpp deleted file mode 100755 index 85127e1..0000000 --- a/example/node_iterator3.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) -#ifndef NODE_ITERATOR3_DWA2004110_HPP -# define NODE_ITERATOR3_DWA2004110_HPP - -# include "node.hpp" -# include - -# ifndef BOOST_NO_SFINAE -# include -# include -# endif - -template -class node_iter - : public boost::iterator_adaptor< - node_iter // Derived - , Value* // Base - , boost::use_default // Value - , boost::forward_traversal_tag // CategoryOrTraversal - > -{ - private: - struct enabler {}; // a private type avoids misuse - - typedef boost::iterator_adaptor< - node_iter, Value*, boost::use_default, boost::forward_traversal_tag - > super_t; - - public: - node_iter() - : super_t(0) {} - - explicit node_iter(Value* p) - : super_t(p) {} - - template - node_iter( - node_iter const& other -# ifndef BOOST_NO_SFINAE - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() -# endif - ) - : super_t(other.base()) {} - -# if !BOOST_WORKAROUND(__GNUC__, == 2) - private: // GCC2 can't grant friendship to template member functions - friend class boost::iterator_core_access; -# endif - void increment() { this->base_reference() = this->base()->next(); } -}; - -typedef node_iter node_iterator; -typedef node_iter node_const_iterator; - -#endif // NODE_ITERATOR3_DWA2004110_HPP diff --git a/example/permutation_iter_example.cpp b/example/permutation_iter_example.cpp deleted file mode 100644 index e6ff889..0000000 --- a/example/permutation_iter_example.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2004 Jeremy Siek -// 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) - -#include -#include -#include -#include -#include -#include - - -int main() { - using namespace boost; - int i = 0; - - typedef std::vector< int > element_range_type; - typedef std::deque< int > index_type; - - static const int element_range_size = 10; - static const int index_size = 4; - - element_range_type elements( element_range_size ); - for(element_range_type::iterator el_it = elements.begin() ; el_it != elements.end() ; ++el_it) - *el_it = std::distance(elements.begin(), el_it); - - index_type indices( index_size ); - for(index_type::iterator i_it = indices.begin() ; i_it != indices.end() ; ++i_it ) - *i_it = element_range_size - index_size + std::distance(indices.begin(), i_it); - std::reverse( indices.begin(), indices.end() ); - - typedef permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type; - permutation_type begin = make_permutation_iterator( elements.begin(), indices.begin() ); - permutation_type it = begin; - permutation_type end = make_permutation_iterator( elements.begin(), indices.end() ); - - std::cout << "The original range is : "; - std::copy( elements.begin(), elements.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The reindexing scheme is : "; - std::copy( indices.begin(), indices.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The permutated range is : "; - std::copy( begin, end, std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "Elements at even indices in the permutation : "; - it = begin; - for(i = 0; i < index_size / 2 ; ++i, it+=2 ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Permutation backwards : "; - it = begin + (index_size); - assert( it != begin ); - for( ; it-- != begin ; ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Iterate backward with stride 2 : "; - it = begin + (index_size - 1); - for(i = 0 ; i < index_size / 2 ; ++i, it-=2 ) std::cout << *it << " "; - std::cout << "\n"; - - return boost::exit_success; -} diff --git a/example/reverse_iterator.cpp b/example/reverse_iterator.cpp deleted file mode 100644 index b5f10f7..0000000 --- a/example/reverse_iterator.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2004 Jeremy Siek -// 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) - -#include -#include -#include -#include -#include - -int main() -{ - int x[] = { 1, 2, 3, 4 }; - boost::reverse_iterator first(x + 4), last(x); - std::copy(first, last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - return 0; -} diff --git a/example/reverse_iterator_example.cpp b/example/reverse_iterator_example.cpp deleted file mode 100644 index 61b8c4f..0000000 --- a/example/reverse_iterator_example.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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) - -#include -#include -#include -#include -#include - -int main(int, char*[]) -{ - char letters_[] = "hello world!"; - const int N = sizeof(letters_)/sizeof(char) - 1; - typedef char* base_iterator; - base_iterator letters(letters_); - - std::cout << "original sequence of letters:\t\t\t" - << letters_ << std::endl; - - // Use reverse_iterator to print a sequence of letters in reverse - // order. - - boost::reverse_iterator - reverse_letters_first(letters + N), - reverse_letters_last(letters); - - std::cout << "sequence in reverse order:\t\t\t"; - std::copy(reverse_letters_first, reverse_letters_last, - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - std::cout << "sequence in double-reversed (normal) order:\t"; - std::copy(boost::make_reverse_iterator(reverse_letters_last), - boost::make_reverse_iterator(reverse_letters_first), - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - return boost::exit_success; -} diff --git a/example/transform_iterator_example.cpp b/example/transform_iterator_example.cpp deleted file mode 100644 index 6f51f01..0000000 --- a/example/transform_iterator_example.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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) - - -#include -#include -#include -#include - -// What a bummer. We can't use std::binder1st with transform iterator -// because it does not have a default constructor. Here's a version -// that does. - -namespace boost { - - template - class binder1st - : public std::unary_function { - protected: - Operation op; - typename Operation::first_argument_type value; - public: - binder1st() { } // this had to be added! - binder1st(const Operation& x, - const typename Operation::first_argument_type& y) - : op(x), value(y) {} - typename Operation::result_type - operator()(const typename Operation::second_argument_type& x) const { - return op(value, x); - } - }; - - template - inline binder1st bind1st(const Operation& op, const T& x) { - typedef typename Operation::first_argument_type arg1_type; - return binder1st(op, arg1_type(x)); - } - -} // namespace boost - -int -main(int, char*[]) -{ - // This is a simple example of using the transform_iterators class to - // generate iterators that multiply the value returned by dereferencing - // the iterator. In this case we are multiplying by 2. - // Would be cooler to use lambda library in this example. - - int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; - const int N = sizeof(x)/sizeof(int); - - typedef boost::binder1st< std::multiplies > Function; - typedef boost::transform_iterator doubling_iterator; - - doubling_iterator i(x, boost::bind1st(std::multiplies(), 2)), - i_end(x + N, boost::bind1st(std::multiplies(), 2)); - - std::cout << "multiplying the array by 2:" << std::endl; - while (i != i_end) - std::cout << *i++ << " "; - std::cout << std::endl; - - std::cout << "adding 4 to each element in the array:" << std::endl; - - std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus(), 4)), - boost::make_transform_iterator(x + N, boost::bind1st(std::plus(), 4)), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - return 0; -} - - diff --git a/include/boost/function_output_iterator.hpp b/include/boost/function_output_iterator.hpp deleted file mode 100644 index 9720f3f..0000000 --- a/include/boost/function_output_iterator.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// (C) Copyright Jeremy Siek 2001. -// 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) - -// Revision History: - -// 27 Feb 2001 Jeremy Siek -// Initial checkin. - -#ifndef BOOST_FUNCTION_OUTPUT_ITERATOR_HPP -#define BOOST_FUNCTION_OUTPUT_ITERATOR_HPP - -#include - -namespace boost { - - template - class function_output_iterator { - typedef function_output_iterator self; - public: - typedef std::output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - - explicit function_output_iterator() {} - - explicit function_output_iterator(const UnaryFunction& f) - : m_f(f) {} - - struct output_proxy { - output_proxy(UnaryFunction& f) : m_f(f) { } - template output_proxy& operator=(const T& value) { - m_f(value); - return *this; - } - UnaryFunction& m_f; - }; - output_proxy operator*() { return output_proxy(m_f); } - self& operator++() { return *this; } - self& operator++(int) { return *this; } - private: - UnaryFunction m_f; - }; - - template - inline function_output_iterator - make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) { - return function_output_iterator(f); - } - -} // namespace boost - -#endif // BOOST_FUNCTION_OUTPUT_ITERATOR_HPP diff --git a/include/boost/pending/detail/int_iterator.hpp b/include/boost/pending/detail/int_iterator.hpp deleted file mode 100644 index e3bae34..0000000 --- a/include/boost/pending/detail/int_iterator.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// (C) Copyright Jeremy Siek 1999. -// 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) - -#ifndef BOOST_INT_ITERATOR_H -#define BOOST_INT_ITERATOR_H - -#include -#if !defined BOOST_MSVC -#include -#endif -#include -//using namespace std; - -#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE -namespace boost { -#endif - -// this should use random_access_iterator_helper but I've had -// VC++ portablility problems with that. -JGS -template -class int_iterator -{ - typedef int_iterator self; -public: - typedef std::random_access_iterator_tag iterator_category; - typedef IntT value_type; - typedef IntT& reference; - typedef IntT* pointer; - typedef std::ptrdiff_t difference_type; - - inline int_iterator() : _i(0) { } - inline int_iterator(IntT i) : _i(i) { } - inline int_iterator(const self& x) : _i(x._i) { } - inline self& operator=(const self& x) { _i = x._i; return *this; } - inline IntT operator*() { return _i; } - inline IntT operator[](IntT n) { return _i + n; } - inline self& operator++() { ++_i; return *this; } - inline self operator++(int) { self t = *this; ++_i; return t; } - inline self& operator+=(IntT n) { _i += n; return *this; } - inline self operator+(IntT n) { self t = *this; t += n; return t; } - inline self& operator--() { --_i; return *this; } - inline self operator--(int) { self t = *this; --_i; return t; } - inline self& operator-=(IntT n) { _i -= n; return *this; } - inline IntT operator-(const self& x) const { return _i - x._i; } - inline bool operator==(const self& x) const { return _i == x._i; } - // vc++ had a problem finding != in random_access_iterator_helper - // need to look into this... for now implementing everything here -JGS - inline bool operator!=(const self& x) const { return _i != x._i; } - inline bool operator<(const self& x) const { return _i < x._i; } - inline bool operator<=(const self& x) const { return _i <= x._i; } - inline bool operator>(const self& x) const { return _i > x._i; } - inline bool operator>=(const self& x) const { return _i >= x._i; } -protected: - IntT _i; -}; - -template -inline int_iterator -operator+(IntT n, int_iterator t) { t += n; return t; } - -#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE -} /* namespace boost */ -#endif - -#ifdef BOOST_NO_OPERATORS_IN_NAMESPACE -namespace boost { - using ::int_iterator; -} -#endif - - -#endif /* BOOST_INT_ITERATOR_H */ diff --git a/include/boost/pending/integer_range.hpp b/include/boost/pending/integer_range.hpp deleted file mode 100644 index 229cbd8..0000000 --- a/include/boost/pending/integer_range.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// (C) Copyright David Abrahams and Jeremy Siek 2000-2001. -// 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) -// -// Revision History: -// 04 Jan 2001 Factored counting_iterator stuff into -// boost/counting_iterator.hpp (David Abrahams) - -#ifndef BOOST_INTEGER_RANGE_HPP_ -#define BOOST_INTEGER_RANGE_HPP_ - -#include -#include -#include - -namespace boost { - -//============================================================================= -// Counting Iterator and Integer Range Class - -template -struct integer_range { - typedef counting_iterator iterator; - - typedef iterator const_iterator; - typedef IntegerType value_type; - typedef std::ptrdiff_t difference_type; - typedef IntegerType reference; - typedef IntegerType const_reference; - typedef const IntegerType* pointer; - typedef const IntegerType* const_pointer; - typedef IntegerType size_type; - - integer_range(IntegerType start, IntegerType finish) - : m_start(start), m_finish(finish) { } - - iterator begin() const { return iterator(m_start); } - iterator end() const { return iterator(m_finish); } - size_type size() const { return m_finish - m_start; } - bool empty() const { return m_finish == m_start; } - void swap(integer_range& x) { - std::swap(m_start, x.m_start); - std::swap(m_finish, x.m_finish); - } -protected: - IntegerType m_start, m_finish; -}; - -template -inline integer_range -make_integer_range(IntegerType first, IntegerType last) -{ - return integer_range(first, last); -} - -} // namespace boost - -#endif // BOOST_INTEGER_RANGE_HPP_ diff --git a/include/boost/pending/iterator_adaptors.hpp b/include/boost/pending/iterator_adaptors.hpp deleted file mode 100644 index 2256e81..0000000 --- a/include/boost/pending/iterator_adaptors.hpp +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright David Abrahams 2003. -// 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) - -#include diff --git a/include/boost/pending/iterator_tests.hpp b/include/boost/pending/iterator_tests.hpp deleted file mode 100644 index dd5fe2d..0000000 --- a/include/boost/pending/iterator_tests.hpp +++ /dev/null @@ -1,268 +0,0 @@ -// Copyright David Abrahams and Jeremy Siek 2003. -// 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) -#ifndef BOOST_ITERATOR_TESTS_HPP -# define BOOST_ITERATOR_TESTS_HPP - -// This is meant to be the beginnings of a comprehensive, generic -// test suite for STL concepts such as iterators and containers. -// -// Revision History: -// 28 Apr 2002 Fixed input iterator requirements. -// For a == b a++ == b++ is no longer required. -// See 24.1.1/3 for details. -// (Thomas Witt) -// 08 Feb 2001 Fixed bidirectional iterator test so that -// --i is no longer a precondition. -// (Jeremy Siek) -// 04 Feb 2001 Added lvalue test, corrected preconditions -// (David Abrahams) - -# include -# include -# include -# include -# include // for detail::dummy_constructor -# include -# include - -namespace boost { - - // use this for the value type -struct dummyT { - dummyT() { } - dummyT(detail::dummy_constructor) { } - dummyT(int x) : m_x(x) { } - int foo() const { return m_x; } - bool operator==(const dummyT& d) const { return m_x == d.m_x; } - int m_x; -}; - -} - -BOOST_TT_BROKEN_COMPILER_SPEC(boost::dummyT) - -namespace boost { - -// Tests whether type Iterator satisfies the requirements for a -// TrivialIterator. -// Preconditions: i != j, *i == val -template -void trivial_iterator_test(const Iterator i, const Iterator j, T val) -{ - Iterator k; - assert(i == i); - assert(j == j); - assert(i != j); -#ifdef BOOST_NO_STD_ITERATOR_TRAITS - T v = *i; -#else - typename std::iterator_traits::value_type v = *i; -#endif - assert(v == val); -#if 0 - // hmm, this will give a warning for transform_iterator... perhaps - // this should be separated out into a stand-alone test since there - // are several situations where it can't be used, like for - // integer_range::iterator. - assert(v == i->foo()); -#endif - k = i; - assert(k == k); - assert(k == i); - assert(k != j); - assert(*k == val); -} - - -// Preconditions: i != j -template -void mutable_trivial_iterator_test(const Iterator i, const Iterator j, T val) -{ - *i = val; - trivial_iterator_test(i, j, val); -} - - -// Preconditions: *i == v1, *++i == v2 -template -void input_iterator_test(Iterator i, T v1, T v2) -{ - Iterator i1(i); - - assert(i == i1); - assert(!(i != i1)); - - // I can see no generic way to create an input iterator - // that is in the domain of== of i and != i. - // The following works for istream_iterator but is not - // guaranteed to work for arbitrary input iterators. - // - // Iterator i2; - // - // assert(i != i2); - // assert(!(i == i2)); - - assert(*i1 == v1); - assert(*i == v1); - - // we cannot test for equivalence of (void)++i & (void)i++ - // as i is only guaranteed to be single pass. - assert(*i++ == v1); - - i1 = i; - - assert(i == i1); - assert(!(i != i1)); - - assert(*i1 == v2); - assert(*i == v2); - - // i is dereferencable, so it must be incrementable. - ++i; - - // how to test for operator-> ? -} - -// how to test output iterator? - - -template struct lvalue_test -{ - template static void check(Iterator) - { -# ifndef BOOST_NO_STD_ITERATOR_TRAITS - typedef typename std::iterator_traits::reference reference; - typedef typename std::iterator_traits::value_type value_type; -# else - typedef typename Iterator::reference reference; - typedef typename Iterator::value_type value_type; -# endif - BOOST_STATIC_ASSERT(boost::is_reference::value); - BOOST_STATIC_ASSERT((boost::is_same::value - || boost::is_same::value - )); - } -}; - -# ifdef BOOST_NO_STD_ITERATOR_TRAITS -template <> struct lvalue_test { - template static void check(T) {} -}; -#endif - -template -void forward_iterator_test(Iterator i, T v1, T v2) -{ - input_iterator_test(i, v1, v2); - - Iterator i1 = i, i2 = i; - - assert(i == i1++); - assert(i != ++i2); - - trivial_iterator_test(i, i1, v1); - trivial_iterator_test(i, i2, v1); - - ++i; - assert(i == i1); - assert(i == i2); - ++i1; - ++i2; - - trivial_iterator_test(i, i1, v2); - trivial_iterator_test(i, i2, v2); - - // borland doesn't allow non-type template parameters -# if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551) - lvalue_test<(boost::is_pointer::value)>::check(i); -#endif -} - -// Preconditions: *i == v1, *++i == v2 -template -void bidirectional_iterator_test(Iterator i, T v1, T v2) -{ - forward_iterator_test(i, v1, v2); - ++i; - - Iterator i1 = i, i2 = i; - - assert(i == i1--); - assert(i != --i2); - - trivial_iterator_test(i, i1, v2); - trivial_iterator_test(i, i2, v2); - - --i; - assert(i == i1); - assert(i == i2); - ++i1; - ++i2; - - trivial_iterator_test(i, i1, v1); - trivial_iterator_test(i, i2, v1); -} - -// mutable_bidirectional_iterator_test - -template struct undefined; - -// Preconditions: [i,i+N) is a valid range -template -void random_access_iterator_test(Iterator i, int N, TrueVals vals) -{ - bidirectional_iterator_test(i, vals[0], vals[1]); - const Iterator j = i; - int c; - - typedef typename boost::detail::iterator_traits::value_type value_type; - - for (c = 0; c < N-1; ++c) { - assert(i == j + c); - assert(*i == vals[c]); - assert(*i == boost::implicit_cast(j[c])); - assert(*i == *(j + c)); - assert(*i == *(c + j)); - ++i; - assert(i > j); - assert(i >= j); - assert(j <= i); - assert(j < i); - } - - Iterator k = j + N - 1; - for (c = 0; c < N-1; ++c) { - assert(i == k - c); - assert(*i == vals[N - 1 - c]); - assert(*i == boost::implicit_cast(j[N - 1 - c])); - Iterator q = k - c; - assert(*i == *q); - assert(i > j); - assert(i >= j); - assert(j <= i); - assert(j < i); - --i; - } -} - -// Precondition: i != j -template -void const_nonconst_iterator_test(Iterator i, ConstIterator j) -{ - assert(i != j); - assert(j != i); - - ConstIterator k(i); - assert(k == i); - assert(i == k); - - k = i; - assert(k == i); - assert(i == k); -} - -} // namespace boost - -#endif // BOOST_ITERATOR_TESTS_HPP diff --git a/include/boost/pointee.hpp b/include/boost/pointee.hpp deleted file mode 100755 index 9794b8e..0000000 --- a/include/boost/pointee.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef POINTEE_DWA200415_HPP -# define POINTEE_DWA200415_HPP - -// -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) -// -// typename pointee

::type provides the pointee type of P. -// -// For example, it is T for T* and X for shared_ptr. -// -// http://www.boost.org/libs/iterator/doc/pointee.html -// - -# include -# include -# include -# include -# include -# include - -namespace boost { - -namespace detail -{ - template - struct smart_ptr_pointee - { - typedef typename P::element_type type; - }; - - template - struct iterator_pointee - { - typedef typename iterator_traits::value_type value_type; - - struct impl - { - template - static char test(T const&); - - static char (& test(value_type&) )[2]; - - static Iterator& x; - }; - - BOOST_STATIC_CONSTANT(bool, is_constant = sizeof(impl::test(*impl::x)) == 1); - - typedef typename mpl::if_c< -# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - ::boost::detail::iterator_pointee::is_constant -# else - is_constant -# endif - , typename add_const::type - , value_type - >::type type; - }; -} - -template -struct pointee - : mpl::eval_if< - detail::is_incrementable

- , detail::iterator_pointee

- , detail::smart_ptr_pointee

- > -{ -}; - -} // namespace boost - -#endif // POINTEE_DWA200415_HPP diff --git a/include/boost/shared_container_iterator.hpp b/include/boost/shared_container_iterator.hpp deleted file mode 100644 index 7d8ecd3..0000000 --- a/include/boost/shared_container_iterator.hpp +++ /dev/null @@ -1,62 +0,0 @@ -// (C) Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and -// distribute this software is granted provided this copyright notice appears -// in all copies. This software is provided "as is" without express or implied -// warranty, and with no claim as to its suitability for any purpose. - -// See http://www.boost.org/libs/utility/shared_container_iterator.html for documentation. - -#ifndef SHARED_CONTAINER_ITERATOR_RG08102002_HPP -#define SHARED_CONTAINER_ITERATOR_RG08102002_HPP - -#include "boost/iterator_adaptors.hpp" -#include "boost/shared_ptr.hpp" -#include - -namespace boost { - -template -class shared_container_iterator : public iterator_adaptor< - shared_container_iterator, - typename Container::iterator> { - - typedef iterator_adaptor< - shared_container_iterator, - typename Container::iterator> super_t; - - typedef typename Container::iterator iterator_t; - typedef boost::shared_ptr container_ref_t; - - container_ref_t container_ref; -public: - shared_container_iterator() { } - - shared_container_iterator(iterator_t const& x,container_ref_t const& c) : - super_t(x), container_ref(c) { } - - -}; - -template -shared_container_iterator -make_shared_container_iterator(typename Container::iterator iter, - boost::shared_ptr const& container) { - typedef shared_container_iterator iterator; - return iterator(iter,container); -} - - - -template -std::pair< - shared_container_iterator, - shared_container_iterator > -make_shared_container_range(boost::shared_ptr const& container) { - return - std::make_pair( - make_shared_container_iterator(container->begin(),container), - make_shared_container_iterator(container->end(),container)); -} - - -} // namespace boost -#endif // SHARED_CONTAINER_ITERATOR_RG08102002_HPP diff --git a/index.html b/index.html deleted file mode 100755 index 71517c4..0000000 --- a/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - -Automatically loading index page... if nothing happens, please go to -doc/index.html. - - - - - diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 deleted file mode 100644 index 8503b2b..0000000 --- a/test/Jamfile.v2 +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright David Abrahams 2003. 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) - -test-suite iterator - : - # These first two tests will run last, and are expected to fail - # for many less-capable compilers. - - [ compile-fail interoperable_fail.cpp ] - # test uses expected success, so that we catch unrelated - # compilation problems. - [ run is_convertible_fail.cpp ] - - [ run zip_iterator_test.cpp - : : : - - # stlport's debug mode generates long symbols which overwhelm - # vc6 - #<*>release - ] - - # These tests should work for just about everything. - [ compile is_lvalue_iterator.cpp ] - [ compile is_readable_iterator.cpp ] - [ compile pointee.cpp ] - - [ run unit_tests.cpp ] - [ run concept_tests.cpp ] - [ run iterator_adaptor_cc.cpp ] - [ run iterator_adaptor_test.cpp ] - [ compile iterator_archetype_cc.cpp ] - [ compile-fail iter_archetype_default_ctor.cpp ] - [ compile-fail lvalue_concept_fail.cpp ] - [ run transform_iterator_test.cpp ] - [ run indirect_iterator_test.cpp ] - [ compile indirect_iter_member_types.cpp ] - [ run filter_iterator_test.cpp ] - [ run iterator_facade.cpp ] - [ run reverse_iterator_test.cpp ] - [ run counting_iterator_test.cpp ] - [ run interoperable.cpp ] - [ run iterator_traits_test.cpp ] - [ run permutation_iterator_test.cpp : : : # on - ] - -; diff --git a/test/concept_tests.cpp b/test/concept_tests.cpp deleted file mode 100644 index f3d518a..0000000 --- a/test/concept_tests.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// (C) Copyright Jeremy Siek 2002. -// 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) - -#include -#include -#include - -struct new_random_access - : std::random_access_iterator_tag - , boost::random_access_traversal_tag -{}; - -struct new_iterator - : public boost::iterator< new_random_access, int > -{ - int& operator*() const { return *m_x; } - new_iterator& operator++() { return *this; } - new_iterator operator++(int) { return *this; } - new_iterator& operator--() { return *this; } - new_iterator operator--(int) { return *this; } - new_iterator& operator+=(std::ptrdiff_t) { return *this; } - new_iterator operator+(std::ptrdiff_t) { return *this; } - new_iterator& operator-=(std::ptrdiff_t) { return *this; } - std::ptrdiff_t operator-(const new_iterator&) const { return 0; } - new_iterator operator-(std::ptrdiff_t) const { return *this; } - bool operator==(const new_iterator&) const { return false; } - bool operator!=(const new_iterator&) const { return false; } - bool operator<(const new_iterator&) const { return false; } - int* m_x; -}; -new_iterator operator+(std::ptrdiff_t, new_iterator x) { return x; } - -struct old_iterator - : public boost::iterator -{ - int& operator*() const { return *m_x; } - old_iterator& operator++() { return *this; } - old_iterator operator++(int) { return *this; } - old_iterator& operator--() { return *this; } - old_iterator operator--(int) { return *this; } - old_iterator& operator+=(std::ptrdiff_t) { return *this; } - old_iterator operator+(std::ptrdiff_t) { return *this; } - old_iterator& operator-=(std::ptrdiff_t) { return *this; } - old_iterator operator-(std::ptrdiff_t) const { return *this; } - std::ptrdiff_t operator-(const old_iterator&) const { return 0; } - bool operator==(const old_iterator&) const { return false; } - bool operator!=(const old_iterator&) const { return false; } - bool operator<(const old_iterator&) const { return false; } - int* m_x; -}; -old_iterator operator+(std::ptrdiff_t, old_iterator x) { return x; } - -int -main() -{ - boost::iterator_traversal::type tc; - boost::random_access_traversal_tag derived = tc; - (void)derived; - - boost::function_requires< - boost_concepts::WritableIteratorConcept >(); - boost::function_requires< - boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< - boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::WritableIteratorConcept >(); - boost::function_requires< - boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::WritableIteratorConcept >(); - boost::function_requires< - boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::InteroperableIteratorConcept >(); - - return 0; -} diff --git a/test/constant_iter_arrow.cpp b/test/constant_iter_arrow.cpp deleted file mode 100755 index 3579c53..0000000 --- a/test/constant_iter_arrow.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright David Abrahams 2004. 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) - -#include -#include - -struct my_iter : boost::iterator_adaptor const*> -{ - my_iter(std::pair const*); - my_iter(); -}; - -std::pair const x(1,1); -my_iter p(&x); -int y = p->first; // operator-> attempts to return an non-const pointer diff --git a/test/constant_iter_arrow_fail.cpp b/test/constant_iter_arrow_fail.cpp deleted file mode 100755 index 05f551a..0000000 --- a/test/constant_iter_arrow_fail.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright David Abrahams 2004. 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) - -#include -#include - -struct my_iter : boost::iterator_adaptor const*> -{ - my_iter(std::pair const*); - my_iter(); -}; - -std::pair const x(1,1); -my_iter p(&x); - -void test() -{ - p->first = 3; -} diff --git a/test/counting_iterator_test.cpp b/test/counting_iterator_test.cpp deleted file mode 100644 index 7770af5..0000000 --- a/test/counting_iterator_test.cpp +++ /dev/null @@ -1,300 +0,0 @@ -// (C) Copyright David Abrahams 2001. -// 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) -// -// See http://www.boost.org for most recent version including documentation. -// -// Revision History -// 16 Feb 2001 Added a missing const. Made the tests run (somewhat) with -// plain MSVC again. (David Abrahams) -// 11 Feb 2001 #if 0'd out use of counting_iterator on non-numeric types in -// MSVC without STLport, so that the other tests may proceed -// (David Abrahams) -// 04 Feb 2001 Added use of iterator_tests.hpp (David Abrahams) -// 28 Jan 2001 Removed not_an_iterator detritus (David Abrahams) -// 24 Jan 2001 Initial revision (David Abrahams) - -#include - -#ifdef __BORLANDC__ // Borland mis-detects our custom iterators -# pragma warn -8091 // template argument ForwardIterator passed to '...' is a output iterator -# pragma warn -8071 // Conversion may lose significant digits (due to counting_iterator += n). -#endif - -#ifdef BOOST_MSVC -# pragma warning(disable:4786) // identifier truncated in debug info -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#ifndef __BORLANDC__ -# include -#endif -#include -#include -#include -#ifndef BOOST_NO_SLIST -# ifdef BOOST_SLIST_HEADER -# include BOOST_SLIST_HEADER -# else -# include -# endif -#endif - - -#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS -template -struct signed_assert_nonnegative -{ - static void test(T x) { BOOST_TEST(x >= 0); } -}; - -template -struct unsigned_assert_nonnegative -{ - static void test(T x) {} -}; - -template -struct assert_nonnegative - : boost::mpl::if_c< - std::numeric_limits::is_signed - , signed_assert_nonnegative - , unsigned_assert_nonnegative - >::type -{ -}; -#endif - -// Special tests for RandomAccess CountingIterators. -template -void category_test( - CountingIterator start, - CountingIterator finish, - Value, - std::random_access_iterator_tag) -{ - typedef typename - boost::detail::iterator_traits::difference_type - difference_type; - difference_type distance = boost::detail::distance(start, finish); - - // Pick a random position internal to the range - difference_type offset = (unsigned)rand() % distance; - -#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS - BOOST_TEST(offset >= 0); -#else - assert_nonnegative::test(offset); -#endif - - CountingIterator internal = start; - std::advance(internal, offset); - - // Try some binary searches on the range to show that it's ordered - BOOST_TEST(std::binary_search(start, finish, *internal)); - - // #including tuple crashed borland, so I had to give up on tie(). - std::pair xy( - std::equal_range(start, finish, *internal)); - CountingIterator x = xy.first, y = xy.second; - - BOOST_TEST(boost::detail::distance(x, y) == 1); - - // Show that values outside the range can't be found - BOOST_TEST(!std::binary_search(start, boost::prior(finish), *finish)); - - // Do the generic random_access_iterator_test - typedef typename CountingIterator::value_type value_type; - std::vector v; - for (value_type z = *start; !(z == *finish); ++z) - v.push_back(z); - - // Note that this test requires a that the first argument is - // dereferenceable /and/ a valid iterator prior to the first argument - boost::random_access_iterator_test(start, v.size(), v.begin()); -} - -// Special tests for bidirectional CountingIterators -template -void category_test(CountingIterator start, Value v1, std::bidirectional_iterator_tag) -{ - Value v2 = v1; - ++v2; - - // Note that this test requires a that the first argument is - // dereferenceable /and/ a valid iterator prior to the first argument - boost::bidirectional_iterator_test(start, v1, v2); -} - -template -void category_test(CountingIterator start, CountingIterator finish, Value v1, std::forward_iterator_tag) -{ - Value v2 = v1; - ++v2; - if (finish != start && finish != boost::next(start)) - boost::forward_readable_iterator_test(start, finish, v1, v2); -} - -template -void test_aux(CountingIterator start, CountingIterator finish, Value v1) -{ - typedef typename CountingIterator::iterator_category category; - typedef typename CountingIterator::value_type value_type; - - // If it's a RandomAccessIterator we can do a few delicate tests - category_test(start, finish, v1, category()); - - // Okay, brute force... - for (CountingIterator p = start - ; p != finish && boost::next(p) != finish - ; ++p) - { - BOOST_TEST(boost::next(*p) == *boost::next(p)); - } - - // prove that a reference can be formed to these values - typedef typename CountingIterator::value_type value; - const value* q = &*start; - (void)q; // suppress unused variable warning -} - -template -void test(Incrementable start, Incrementable finish) -{ - test_aux(boost::make_counting_iterator(start), boost::make_counting_iterator(finish), start); -} - -template -void test_integer(Integer* = 0) // default arg works around MSVC bug -{ - Integer start = 0; - Integer finish = 120; - test(start, finish); -} - -template -void test_integer3(Integer* = 0, Category* = 0, Difference* = 0) // default arg works around MSVC bug -{ - Integer start = 0; - Integer finish = 120; - typedef boost::counting_iterator iterator; - test_aux(iterator(start), iterator(finish), start); -} - -template -void test_container(Container* = 0) // default arg works around MSVC bug -{ - Container c(1 + (unsigned)rand() % 1673); - - const typename Container::iterator start = c.begin(); - - // back off by 1 to leave room for dereferenceable value at the end - typename Container::iterator finish = start; - std::advance(finish, c.size() - 1); - - test(start, finish); - - typedef typename Container::const_iterator const_iterator; - test(const_iterator(start), const_iterator(finish)); -} - -class my_int1 { -public: - my_int1() { } - my_int1(int x) : m_int(x) { } - my_int1& operator++() { ++m_int; return *this; } - bool operator==(const my_int1& x) const { return m_int == x.m_int; } -private: - int m_int; -}; - -class my_int2 { -public: - typedef void value_type; - typedef void pointer; - typedef void reference; - typedef std::ptrdiff_t difference_type; - typedef std::bidirectional_iterator_tag iterator_category; - - my_int2() { } - my_int2(int x) : m_int(x) { } - my_int2& operator++() { ++m_int; return *this; } - my_int2& operator--() { --m_int; return *this; } - bool operator==(const my_int2& x) const { return m_int == x.m_int; } -private: - int m_int; -}; - -class my_int3 { -public: - typedef void value_type; - typedef void pointer; - typedef void reference; - typedef std::ptrdiff_t difference_type; - typedef std::random_access_iterator_tag iterator_category; - - my_int3() { } - my_int3(int x) : m_int(x) { } - my_int3& operator++() { ++m_int; return *this; } - my_int3& operator+=(std::ptrdiff_t n) { m_int += n; return *this; } - std::ptrdiff_t operator-(const my_int3& x) const { return m_int - x.m_int; } - my_int3& operator--() { --m_int; return *this; } - bool operator==(const my_int3& x) const { return m_int == x.m_int; } - bool operator!=(const my_int3& x) const { return m_int != x.m_int; } - bool operator<(const my_int3& x) const { return m_int < x.m_int; } -private: - int m_int; -}; - -int main() -{ - // Test the built-in integer types. - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); -#if defined(BOOST_HAS_LONG_LONG) - test_integer< ::boost::long_long_type>(); - test_integer< ::boost::ulong_long_type>(); -#endif - - // Test user-defined type. - - test_integer3(); - test_integer3(); - test_integer(); - test_integer(); - - // Some tests on container iterators, to prove we handle a few different categories - test_container >(); - test_container >(); -# ifndef BOOST_NO_SLIST - test_container >(); -# endif - - // Also prove that we can handle raw pointers. - int array[2000]; - test(boost::make_counting_iterator(array), boost::make_counting_iterator(array+2000-1)); - - return boost::report_errors(); -} diff --git a/test/filter_iterator_test.cpp b/test/filter_iterator_test.cpp deleted file mode 100644 index beaab4d..0000000 --- a/test/filter_iterator_test.cpp +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright David Abrahams 2003, Jeremy Siek 2004. - -// 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) - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using boost::dummyT; - -struct one_or_four -{ - bool operator()(dummyT x) const - { - return x.foo() == 1 || x.foo() == 4; - } -}; - -template struct undefined; - -template struct see_type; - -// Test filter iterator -int main() -{ - // Concept checks - // Adapting old-style iterators - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost::OutputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::Mutable_ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::Mutable_BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::Mutable_BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - // Adapting new-style iterators - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_iterator_t - , boost::single_pass_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } -#if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker. - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::single_pass_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost::OutputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } -#endif - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - -#if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker. - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_lvalue_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::writable_lvalue_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::Mutable_ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } -#endif - - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_iterator_t - , boost::random_access_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - -#if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker. - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::random_access_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_lvalue_iterator_t - , boost::random_access_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::writable_lvalue_iterator_t - , boost::random_access_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::Mutable_BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } -#endif - - // Run-time tests - - dummyT array[] = { dummyT(0), dummyT(1), dummyT(2), - dummyT(3), dummyT(4), dummyT(5) }; - const int N = sizeof(array)/sizeof(dummyT); - - typedef boost::filter_iterator filter_iter; - - boost::bidirectional_readable_iterator_test( - filter_iter(one_or_four(), array, array+N) - , dummyT(1), dummyT(4)); - - BOOST_STATIC_ASSERT( - (!boost::is_convertible< - boost::iterator_traversal::type - , boost::random_access_traversal_tag - >::value - )); - - //# endif - - // On compilers not supporting partial specialization, we can do more type - // deduction with deque iterators than with pointers... unless the library - // is broken ;-( - std::deque array2; - std::copy(array+0, array+N, std::back_inserter(array2)); - boost::bidirectional_readable_iterator_test( - boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()), - dummyT(1), dummyT(4)); - - boost::bidirectional_readable_iterator_test( - boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()), - dummyT(1), dummyT(4)); - - boost::bidirectional_readable_iterator_test( - boost::make_filter_iterator( - one_or_four() - , boost::make_reverse_iterator(array2.end()) - , boost::make_reverse_iterator(array2.begin()) - ), - dummyT(4), dummyT(1)); - - boost::bidirectional_readable_iterator_test( - filter_iter(array+0, array+N), - dummyT(1), dummyT(4)); - - boost::bidirectional_readable_iterator_test( - filter_iter(one_or_four(), array, array + N), - dummyT(1), dummyT(4)); - - - return boost::report_errors(); -} diff --git a/test/indirect_iter_member_types.cpp b/test/indirect_iter_member_types.cpp deleted file mode 100644 index 84dcaeb..0000000 --- a/test/indirect_iter_member_types.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// (C) Copyright Jeremy Siek 2004. -// 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) - -// Revision History -// 03 Jan 2004 Jeremy Siek -// First draft. - - -#include -#include - -#include -#include -#include "static_assert_same.hpp" -#include - -struct zow { }; - -struct my_ptr { - typedef zow const element_type; - zow const& operator*() const; -// typedef const zow& reference; -// typedef const zow* pointer; -// typedef void difference_type; -// typedef boost::no_traversal_tag iterator_category; -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(my_ptr) -BOOST_TT_BROKEN_COMPILER_SPEC(zow) - -// Borland 5.6.4 and earlier drop const all over the place, so this -// test will fail in the lines marked with (**) - -int main() -{ - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, int&); - STATIC_ASSERT_SAME(Iter::pointer, int*); - STATIC_ASSERT_SAME(Iter::difference_type, std::ptrdiff_t); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - BOOST_STATIC_ASSERT((boost::is_convertible::type, - boost::random_access_traversal_tag>::value)); - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, const int&); - STATIC_ASSERT_SAME(Iter::pointer, const int*); // (**) - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, int&); - STATIC_ASSERT_SAME(Iter::pointer, int*); - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, const int&); - STATIC_ASSERT_SAME(Iter::pointer, const int*); // (**) - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, zow); - STATIC_ASSERT_SAME(Iter::reference, const zow&); // (**) - STATIC_ASSERT_SAME(Iter::pointer, const zow*); // (**) - - STATIC_ASSERT_SAME(Iter::difference_type, std::ptrdiff_t); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - BOOST_STATIC_ASSERT((boost::is_convertible::type, - boost::random_access_traversal_tag>::value)); - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, long&); - STATIC_ASSERT_SAME(Iter::pointer, int*); - STATIC_ASSERT_SAME(Iter::difference_type, short); - } - return 0; -} diff --git a/test/indirect_iterator_test.cpp b/test/indirect_iterator_test.cpp deleted file mode 100644 index 8cea482..0000000 --- a/test/indirect_iterator_test.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// (C) Copyright Jeremy Siek 1999. -// 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) - -// Revision History -// 22 Nov 2002 Thomas Witt -// Added interoperability check. -// 08 Mar 2001 Jeremy Siek -// Moved test of indirect iterator into its own file. It to -// to be in iterator_adaptor_test.cpp. - -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include - -#include - -#include - -#include -#include -#include - -#if !defined(__SGI_STL_PORT) \ - && (defined(BOOST_MSVC_STD_ITERATOR) \ - || BOOST_WORKAROUND(_CPPLIB_VER, <= 310) \ - || BOOST_WORKAROUND(__GNUC__, <= 2)) - -// std container random-access iterators don't support mutable/const -// interoperability (but may support const/mutable interop). -# define NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY - -#endif - - -template struct see_type; -template struct see_val; - -struct my_iterator_tag : public std::random_access_iterator_tag { }; - -using boost::dummyT; -BOOST_TT_BROKEN_COMPILER_SPEC(boost::shared_ptr) - -typedef std::vector storage; -typedef std::vector pointer_ra_container; -typedef std::set iterator_set; - -template -struct indirect_iterator_pair_generator -{ - typedef boost::indirect_iterator iterator; - - typedef boost::indirect_iterator< - typename Container::iterator - , typename iterator::value_type const - > const_iterator; -}; - -void more_indirect_iterator_tests() -{ - storage store(1000); - std::generate(store.begin(), store.end(), rand); - - pointer_ra_container ptr_ra_container; - iterator_set iter_set; - - for (storage::iterator p = store.begin(); p != store.end(); ++p) - { - ptr_ra_container.push_back(&*p); - iter_set.insert(p); - } - - typedef indirect_iterator_pair_generator indirect_ra_container; - - indirect_ra_container::iterator db(ptr_ra_container.begin()); - indirect_ra_container::iterator de(ptr_ra_container.end()); - BOOST_TEST(static_cast(de - db) == store.size()); - BOOST_TEST(db + store.size() == de); - indirect_ra_container::const_iterator dci = db; - - BOOST_TEST(dci == db); - -#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY - BOOST_TEST(db == dci); -#endif - - BOOST_TEST(dci != de); - BOOST_TEST(dci < de); - BOOST_TEST(dci <= de); - -#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY - BOOST_TEST(de >= dci); - BOOST_TEST(de > dci); -#endif - - dci = de; - BOOST_TEST(dci == de); - - boost::random_access_iterator_test(db + 1, store.size() - 1, boost::next(store.begin())); - - *db = 999; - BOOST_TEST(store.front() == 999); - - // Borland C++ is getting very confused about the typedefs here - typedef boost::indirect_iterator indirect_set_iterator; - typedef boost::indirect_iterator< - iterator_set::iterator - , iterator_set::iterator::value_type const - > const_indirect_set_iterator; - - indirect_set_iterator sb(iter_set.begin()); - indirect_set_iterator se(iter_set.end()); - const_indirect_set_iterator sci(iter_set.begin()); - BOOST_TEST(sci == sb); - -# ifndef NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY - BOOST_TEST(se != sci); -# endif - - BOOST_TEST(sci != se); - sci = se; - BOOST_TEST(sci == se); - - *boost::prior(se) = 888; - BOOST_TEST(store.back() == 888); - BOOST_TEST(std::equal(sb, se, store.begin())); - - boost::bidirectional_iterator_test(boost::next(sb), store[1], store[2]); - BOOST_TEST(std::equal(db, de, store.begin())); -} - -// element_type detector; defaults to true so the test passes when -// has_xxx isn't implemented -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_element_type, element_type, true) - -int -main() -{ - dummyT array[] = { dummyT(0), dummyT(1), dummyT(2), - dummyT(3), dummyT(4), dummyT(5) }; - const int N = sizeof(array)/sizeof(dummyT); - -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - boost::shared_ptr zz((dummyT*)0); // Why? I don't know, but it suppresses a bad instantiation. -# endif - - typedef std::vector > shared_t; - shared_t shared; - - // Concept checks - { - typedef boost::indirect_iterator iter_t; - - BOOST_STATIC_ASSERT( - has_element_type< - boost::detail::iterator_traits::value_type - >::value - ); - - typedef boost::indirect_iterator< - shared_t::iterator - , boost::iterator_value::type const - > c_iter_t; - -# ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); -# endif - } - - // Test indirect_iterator_generator - { - for (int jj = 0; jj < N; ++jj) - shared.push_back(boost::shared_ptr(new dummyT(jj))); - - dummyT* ptr[N]; - for (int k = 0; k < N; ++k) - ptr[k] = array + k; - - typedef boost::indirect_iterator indirect_iterator; - - typedef boost::indirect_iterator - const_indirect_iterator; - - indirect_iterator i(ptr); - boost::random_access_iterator_test(i, N, array); - - boost::random_access_iterator_test( - boost::indirect_iterator(shared.begin()) - , N, array); - - boost::random_access_iterator_test(boost::make_indirect_iterator(ptr), N, array); - - // check operator-> - assert((*i).m_x == i->foo()); - - const_indirect_iterator j(ptr); - boost::random_access_iterator_test(j, N, array); - - dummyT const*const* const_ptr = ptr; - boost::random_access_iterator_test(boost::make_indirect_iterator(const_ptr), N, array); - - boost::const_nonconst_iterator_test(i, ++j); - - more_indirect_iterator_tests(); - } - return boost::report_errors(); -} diff --git a/test/interoperable.cpp b/test/interoperable.cpp deleted file mode 100755 index ba4196a..0000000 --- a/test/interoperable.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) - -#include -#include -#include -#include - -struct mutable_it : boost::iterator_adaptor -{ - typedef boost::iterator_adaptor super_t; - - mutable_it(); - explicit mutable_it(int* p) : super_t(p) {} - - bool equal(mutable_it const& rhs) const - { - return this->base() == rhs.base(); - } -}; - -struct constant_it : boost::iterator_adaptor -{ - typedef boost::iterator_adaptor super_t; - - constant_it(); - explicit constant_it(int* p) : super_t(p) {} - constant_it(mutable_it const& x) : super_t(x.base()) {} - - bool equal(constant_it const& rhs) const - { - return this->base() == rhs.base(); - } -}; - -int main() -{ - int data[] = { 49, 77 }; - - mutable_it i(data); - constant_it j(data + 1); - BOOST_TEST(i < j); - BOOST_TEST(j > i); - BOOST_TEST(i <= j); - BOOST_TEST(j >= i); - BOOST_TEST(j - i == 1); - BOOST_TEST(i - j == -1); - - constant_it k = i; - - BOOST_TEST(!(i < k)); - BOOST_TEST(!(k > i)); - BOOST_TEST(i <= k); - BOOST_TEST(k >= i); - BOOST_TEST(k - i == 0); - BOOST_TEST(i - k == 0); - - return boost::report_errors(); -} diff --git a/test/interoperable_fail.cpp b/test/interoperable_fail.cpp deleted file mode 100644 index d6d249a..0000000 --- a/test/interoperable_fail.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Thomas Witt 2003. -// 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) -#include -#include -#include -#include -#include - -int main() -{ - { - typedef boost::reverse_iterator::iterator> rev_iter; - typedef boost::indirect_iterator::iterator> ind_iter; - - ind_iter() == rev_iter(); - } - - return boost::exit_success; -} diff --git a/test/is_convertible_fail.cpp b/test/is_convertible_fail.cpp deleted file mode 100644 index 757b5c6..0000000 --- a/test/is_convertible_fail.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) Thomas Witt 2002. -// -// Use, modification and distribution is subject to 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) -// -#include -#include - -int main() -{ - typedef boost::reverse_iterator rev_iter1; - typedef boost::reverse_iterator rev_iter2; - - return boost::is_convertible::value - ? boost::exit_failure : boost::exit_success; -} diff --git a/test/is_lvalue_iterator.cpp b/test/is_lvalue_iterator.cpp deleted file mode 100755 index fdace52..0000000 --- a/test/is_lvalue_iterator.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright David Abrahams 2003. Use, modification and distribution is -// subject to 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) - -#include -#include -#include -#include -#include -#include -#include -#include - -// Last, for BOOST_NO_LVALUE_RETURN_DETECTION -#include - -struct v -{ - v(); - ~v(); -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(v) - -struct value_iterator : boost::iterator -{ - v operator*() const; -}; - -struct noncopyable_iterator : boost::iterator -{ - boost::noncopyable const& operator*() const; -}; - -template -struct proxy_iterator - : boost::iterator -{ - typedef T value_type; - -#if BOOST_WORKAROUND(__GNUC__, == 2) - typedef boost::iterator base; - typedef base::iterator_category iterator_category; - typedef base::difference_type difference_type; - typedef base::pointer pointer; - typedef base::reference reference; -#endif - - struct proxy - { - operator value_type&() const; - proxy& operator=(value_type) const; - }; - - proxy operator*() const; -}; - -template -struct lvalue_iterator -{ - typedef T value_type; - typedef T& reference; - typedef T difference_type; - typedef std::input_iterator_tag iterator_category; - typedef T* pointer; - - T& operator*() const; - lvalue_iterator& operator++(); - lvalue_iterator operator++(int); -}; - -template -struct constant_lvalue_iterator -{ - typedef T value_type; - typedef T const& reference; - typedef T difference_type; - typedef std::input_iterator_tag iterator_category; - typedef T const* pointer; - - T const& operator*() const; - constant_lvalue_iterator& operator++(); - constant_lvalue_iterator operator++(int); -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(proxy_iterator::proxy) -BOOST_TT_BROKEN_COMPILER_SPEC(proxy_iterator::proxy) - -int main() -{ - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::iterator>::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::const_iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator > >::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator >::value); -#ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator::value); -#endif - // Make sure inaccessible copy constructor doesn't prevent - // reference binding - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); - - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - - - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - - - - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator::iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::const_iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator > >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); -#ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::value); -#endif - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::value); - - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); -#endif - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); - - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - - return 0; -} diff --git a/test/is_readable_iterator.cpp b/test/is_readable_iterator.cpp deleted file mode 100755 index 15ed099..0000000 --- a/test/is_readable_iterator.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright David Abrahams 2003. Use, modification and distribution is -// subject to 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) - -#include -#include -#include -#include -#include -#include -#include -#include - -// Last, for BOOST_NO_LVALUE_RETURN_DETECTION -#include - -struct v -{ - v(); - ~v(); -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(v) - -struct value_iterator : boost::iterator -{ - v operator*() const; -}; - -struct noncopyable_iterator : boost::iterator -{ - boost::noncopyable const& operator*() const; -}; - -struct proxy_iterator : boost::iterator -{ -#if BOOST_WORKAROUND(__GNUC__, == 2) - typedef boost::iterator base; - typedef base::iterator_category iterator_category; - typedef base::value_type value_type; - typedef base::difference_type difference_type; - typedef base::pointer pointer; - typedef base::reference reference; -#endif - - struct proxy - { - operator v&(); - proxy& operator=(v) const; - }; - - proxy operator*() const; -}; - -struct proxy_iterator2 : boost::iterator -{ -#if BOOST_WORKAROUND(__GNUC__, == 2) - typedef boost::iterator base; - typedef base::iterator_category iterator_category; - typedef base::value_type value_type; - typedef base::difference_type difference_type; - typedef base::pointer pointer; - typedef base::reference reference; -#endif - - struct proxy - { - proxy& operator=(v) const; - }; - - proxy operator*() const; -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(proxy_iterator::proxy) - -int main() -{ - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::iterator>::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::const_iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_readable_iterator > >::value); - BOOST_STATIC_ASSERT(!boost::is_readable_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - BOOST_STATIC_ASSERT(!boost::is_readable_iterator::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - - // Make sure inaccessible copy constructor doesn't prevent - // readability - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - - return 0; -} diff --git a/test/iter_archetype_default_ctor.cpp b/test/iter_archetype_default_ctor.cpp deleted file mode 100755 index 7936bdd..0000000 --- a/test/iter_archetype_default_ctor.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright Thomas Witt 2004. -// 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) -// -#include - - -int main() -{ - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::readable_iterator_t - , boost::single_pass_traversal_tag - > iter; - - // single_pass_traversal iterators are not required to be - // default constructible - iter it; -} diff --git a/test/iterator_adaptor_cc.cpp b/test/iterator_adaptor_cc.cpp deleted file mode 100644 index 599474c..0000000 --- a/test/iterator_adaptor_cc.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2004 Jeremy Siek -// 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) - -#include -#include -#include -#include -#include - -int main() -{ - { - typedef boost::reverse_iterator rev_iter; - typedef boost::reverse_iterator c_rev_iter; - - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - boost::function_requires< boost::RandomAccessIteratorConcept >(); - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); - } - - // Many compilers' builtin container iterators don't interoperate well, though - // STLport fixes that problem. -#if defined(__SGI_STL_PORT) \ - || !BOOST_WORKAROUND(__GNUC__, <= 2) \ - && !(BOOST_WORKAROUND(__GNUC__, == 3) && BOOST_WORKAROUND(__GNUC_MINOR__, <= 1)) \ - && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) \ - && !BOOST_WORKAROUND(__LIBCOMO_VERSION__, BOOST_TESTED_AT(29)) \ - && !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 1) - { - typedef boost::reverse_iterator::iterator> rev_iter; - typedef boost::reverse_iterator::const_iterator> c_rev_iter; - - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); - } -#endif - - return boost::exit_success; -} diff --git a/test/iterator_adaptor_test.cpp b/test/iterator_adaptor_test.cpp deleted file mode 100644 index e339fe1..0000000 --- a/test/iterator_adaptor_test.cpp +++ /dev/null @@ -1,337 +0,0 @@ -// (C) Copyright Thomas Witt 2003. -// 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) - -// See http://www.boost.org for most recent version including documentation. - -#include -#include - -#include -#include -#include - -#include -#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) -# include -# include -#endif -#include - -# include - -# include - -#include -#include -#include -#include -#include - -#include "static_assert_same.hpp" - -#include - -using boost::dummyT; - -struct mult_functor { - typedef int result_type; - typedef int argument_type; - // Functors used with transform_iterator must be - // DefaultConstructible, as the transform_iterator must be - // DefaultConstructible to satisfy the requirements for - // TrivialIterator. - mult_functor() { } - mult_functor(int aa) : a(aa) { } - int operator()(int b) const { return a * b; } - int a; -}; - -template -struct select1st_ - : public std::unary_function -{ - const typename Pair::first_type& operator()(const Pair& x) const { - return x.first; - } - typename Pair::first_type& operator()(Pair& x) const { - return x.first; - } -}; - -struct one_or_four { - bool operator()(dummyT x) const { - return x.foo() == 1 || x.foo() == 4; - } -}; - -typedef std::deque storage; -typedef std::deque pointer_deque; -typedef std::set iterator_set; - -template struct foo; - -void blah(int) { } - -struct my_gen -{ - typedef int result_type; - my_gen() : n(0) { } - int operator()() { return ++n; } - int n; -}; - -template -struct ptr_iterator - : boost::iterator_adaptor< - ptr_iterator - , V* - , V - , boost::random_access_traversal_tag -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - , V& -#endif - > -{ -private: - typedef boost::iterator_adaptor< - ptr_iterator - , V* - , V - , boost::random_access_traversal_tag -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - , V& -#endif - > super_t; - -public: - ptr_iterator() { } - ptr_iterator(V* d) : super_t(d) { } - - template - ptr_iterator( - const ptr_iterator& x - , typename boost::enable_if_convertible::type* = 0 - ) - : super_t(x.base()) - {} -}; - -// Non-functional iterator for category modification checking -template -struct modify_traversal - : boost::iterator_adaptor< - modify_traversal - , Iter - , boost::use_default - , Traversal - > -{}; - -template -struct fwd_iterator - : boost::iterator_adaptor< - fwd_iterator - , boost::forward_iterator_archetype - > -{ -private: - typedef boost::iterator_adaptor< - fwd_iterator - , boost::forward_iterator_archetype - > super_t; - -public: - fwd_iterator() { } - fwd_iterator(boost::forward_iterator_archetype d) : super_t(d) { } -}; - -template -struct in_iterator - : boost::iterator_adaptor< - in_iterator - , boost::input_iterator_archetype_no_proxy - > -{ -private: - typedef boost::iterator_adaptor< - in_iterator - , boost::input_iterator_archetype_no_proxy - > super_t; - -public: - in_iterator() { } - in_iterator(boost::input_iterator_archetype_no_proxy d) : super_t(d) { } -}; - -template -struct constant_iterator - : boost::iterator_adaptor< - constant_iterator - , Iter - , typename std::iterator_traits::value_type const - > -{ - typedef boost::iterator_adaptor< - constant_iterator - , Iter - , typename std::iterator_traits::value_type const - > base_t; - - constant_iterator() {} - constant_iterator(Iter it) - : base_t(it) {} -}; - -char (& traversal2(boost::incrementable_traversal_tag) )[1]; -char (& traversal2(boost::single_pass_traversal_tag ) )[2]; -char (& traversal2(boost::forward_traversal_tag ) )[3]; -char (& traversal2(boost::bidirectional_traversal_tag) )[4]; -char (& traversal2(boost::random_access_traversal_tag) )[5]; - -template -struct traversal3 -{ - static typename boost::iterator_category_to_traversal::type x; - BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(traversal2(x))); - typedef char (&type)[value]; -}; - -template -typename traversal3::type traversal(Cat); - -template -int static_assert_traversal(Iter* = 0, Trav* = 0) -{ - typedef typename boost::iterator_category_to_traversal< - BOOST_DEDUCED_TYPENAME Iter::iterator_category - >::type t2; - - return static_assert_same::value; -} - -int -main() -{ - dummyT array[] = { dummyT(0), dummyT(1), dummyT(2), - dummyT(3), dummyT(4), dummyT(5) }; - const int N = sizeof(array)/sizeof(dummyT); - - // sanity check, if this doesn't pass the test is buggy - boost::random_access_iterator_test(array, N, array); - - // Test the iterator_adaptor - { - ptr_iterator i(array); - boost::random_access_iterator_test(i, N, array); - - ptr_iterator j(array); - boost::random_access_iterator_test(j, N, array); - boost::const_nonconst_iterator_test(i, ++j); - } - - int test; - // Test the iterator_traits - { - // Test computation of defaults - typedef ptr_iterator Iter1; - // don't use std::iterator_traits here to avoid VC++ problems - test = static_assert_same::value; - test = static_assert_same::value; - test = static_assert_same::value; - test = static_assert_same::value; -#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - BOOST_STATIC_ASSERT((boost::is_convertible::value)); -#endif - } - - { - // Test computation of default when the Value is const - typedef ptr_iterator Iter1; - test = static_assert_same::value; - test = static_assert_same::value; - -#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); -# ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); -# endif -#endif - -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // borland drops constness - test = static_assert_same::value; -#endif - } - - { - // Test constant iterator idiom - typedef ptr_iterator BaseIter; - typedef constant_iterator Iter; - - test = static_assert_same::value; - test = static_assert_same::value; -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // borland drops constness - test = static_assert_same::value; -#endif - -#ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); -#endif - - typedef modify_traversal IncrementableIter; - - static_assert_traversal(); - static_assert_traversal(); - } - - // Test the iterator_adaptor - { - ptr_iterator i(array); - boost::random_access_iterator_test(i, N, array); - - ptr_iterator j(array); - boost::random_access_iterator_test(j, N, array); - boost::const_nonconst_iterator_test(i, ++j); - } - - // check operator-> with a forward iterator - { - boost::forward_iterator_archetype forward_iter; - - typedef fwd_iterator adaptor_type; - - adaptor_type i(forward_iter); - int zero = 0; - if (zero) // don't do this, just make sure it compiles - BOOST_TEST((*i).m_x == i->foo()); - } - - // check operator-> with an input iterator - { - boost::input_iterator_archetype_no_proxy input_iter; - typedef in_iterator adaptor_type; - adaptor_type i(input_iter); - int zero = 0; - if (zero) // don't do this, just make sure it compiles - BOOST_TEST((*i).m_x == i->foo()); - } - - // check that base_type is correct - { - // Test constant iterator idiom - typedef ptr_iterator BaseIter; - - test = static_assert_same::value; - test = static_assert_same::base_type,BaseIter>::value; - - typedef modify_traversal IncrementableIter; - - test = static_assert_same::value; - } - - std::cout << "test successful " << std::endl; - (void)test; - return boost::report_errors(); -} diff --git a/test/iterator_archetype_cc.cpp b/test/iterator_archetype_cc.cpp deleted file mode 100644 index 580a32c..0000000 --- a/test/iterator_archetype_cc.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright Thomas Witt 2003. -// 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) -// -#include -#include -#include -#include -#include - -int main() -{ - { - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::readable_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - const int // I don't like adding const to Value. It is redundant. -JGS - , boost::iterator_archetypes::readable_lvalue_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::writable_lvalue_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - - return boost::exit_success; -} - diff --git a/test/iterator_facade.cpp b/test/iterator_facade.cpp deleted file mode 100755 index ed3057e..0000000 --- a/test/iterator_facade.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright David Abrahams 2004. 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) - -// This is really an incomplete test; should be fleshed out. - -#include -#include - -// This is a really, really limited test so far. All we're doing -// right now is checking that the postfix++ proxy for single-pass -// iterators works properly. -template -class counter_iterator - : public boost::iterator_facade< - counter_iterator - , int const - , boost::single_pass_traversal_tag - , Ref - > -{ - public: - counter_iterator() {} - counter_iterator(int* state) : state(state) {} - - void increment() - { - ++*state; - } - - Ref - dereference() const - { - return *state; - } - - bool equal(counter_iterator const& y) const - { - return *this->state == *y.state; - } - - int* state; -}; - -struct proxy -{ - proxy(int& x) : state(x) {} - - operator int const&() const - { - return state; - } - - int& operator=(int x) { state = x; return state; } - - int& state; -}; - -struct value -{ - void mutator() {} // non-const member function -}; - -struct input_iter - : boost::iterator_facade< - input_iter - , value - , boost::single_pass_traversal_tag - , value - > -{ - public: - input_iter() {} - - void increment() - { - } - value - dereference() const - { - return value(); - } - - bool equal(input_iter const& y) const - { - return false; - } -}; - -int main() -{ - int state = 0; - boost::readable_iterator_test(counter_iterator(&state), 0); - state = 3; - boost::readable_iterator_test(counter_iterator(&state), 3); - boost::writable_iterator_test(counter_iterator(&state), 9, 7); - BOOST_TEST(state == 8); - - // test for a fix to http://tinyurl.com/zuohe - // These two lines should be equivalent (and both compile) - input_iter p; - (*p).mutator(); - p->mutator(); - - return boost::report_errors(); -} diff --git a/test/iterator_traits_test.cpp b/test/iterator_traits_test.cpp deleted file mode 100644 index 3131d44..0000000 --- a/test/iterator_traits_test.cpp +++ /dev/null @@ -1,218 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// 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) - -// See http://www.boost.org for most recent version including documentation. - -// Revision History -// 04 Mar 2001 Patches for Intel C++ (Dave Abrahams) -// 19 Feb 2001 Take advantage of improved iterator_traits to do more tests -// on MSVC. Reordered some #ifdefs for coherency. -// (David Abrahams) -// 13 Feb 2001 Test new VC6 workarounds (David Abrahams) -// 11 Feb 2001 Final fixes for Borland (David Abrahams) -// 11 Feb 2001 Some fixes for Borland get it closer on that compiler -// (David Abrahams) -// 07 Feb 2001 More comprehensive testing; factored out static tests for -// better reuse (David Abrahams) -// 21 Jan 2001 Quick fix to my_iterator, which wasn't returning a -// reference type from operator* (David Abrahams) -// 19 Jan 2001 Initial version with iterator operators (David Abrahams) - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// A UDT for which we can specialize std::iterator_traits on -// compilers which don't support partial specialization. There's no -// other reasonable way to test pointers on those compilers. -struct element {}; - -// An iterator for which we can get traits. -struct my_iterator1 - : boost::forward_iterator_helper -{ - my_iterator1(const char* p) : m_p(p) {} - - bool operator==(const my_iterator1& rhs) const - { return this->m_p == rhs.m_p; } - - my_iterator1& operator++() { ++this->m_p; return *this; } - const char& operator*() { return *m_p; } - private: - const char* m_p; -}; - -// Used to prove that we don't require std::iterator<> in the hierarchy under -// MSVC6, and that we can compute all the traits for a standard-conforming UDT -// iterator. -struct my_iterator2 - : boost::equality_comparable > > -{ - typedef char value_type; - typedef long difference_type; - typedef const char* pointer; - typedef const char& reference; - typedef std::forward_iterator_tag iterator_category; - - my_iterator2(const char* p) : m_p(p) {} - - bool operator==(const my_iterator2& rhs) const - { return this->m_p == rhs.m_p; } - - my_iterator2& operator++() { ++this->m_p; return *this; } - const char& operator*() { return *m_p; } - private: - const char* m_p; -}; - -// Used to prove that we're not overly confused by the existence of -// std::iterator<> in the hierarchy under MSVC6 - we should find that -// boost::detail::iterator_traits::difference_type is int. -struct my_iterator3 : my_iterator1 -{ - typedef int difference_type; - my_iterator3(const char* p) - : my_iterator1(p) {} -}; - -// -// Assertion tools. Used instead of BOOST_STATIC_ASSERT because that -// doesn't give us a nice stack backtrace -// -template struct assertion; - -template <> struct assertion -{ - typedef char type; -}; - -template -struct assert_same - : assertion<(::boost::is_same::value)> -{ -}; - - -// Iterator tests -template -struct non_portable_tests -{ - typedef typename boost::detail::iterator_traits::pointer test_pt; - typedef typename boost::detail::iterator_traits::reference test_rt; - typedef typename assert_same::type a1; - typedef typename assert_same::type a2; -}; - -template -struct portable_tests -{ - typedef typename boost::detail::iterator_traits::difference_type test_dt; - typedef typename boost::detail::iterator_traits::iterator_category test_cat; - typedef typename assert_same::type a1; - typedef typename assert_same::type a2; -}; - -// Test iterator_traits -template -struct input_iterator_test - : portable_tests -{ - typedef typename boost::detail::iterator_traits::value_type test_vt; - typedef typename assert_same::type a1; -}; - -template -struct non_pointer_test - : input_iterator_test - , non_portable_tests -{ -}; - -template -struct maybe_pointer_test - : portable_tests - , non_portable_tests -{ -}; - -input_iterator_test, int, std::ptrdiff_t, int*, int&, std::input_iterator_tag> - istream_iterator_test; - -#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564) && !defined(__SGI_STL_PORT) -typedef ::std::char_traits::off_type distance; -non_pointer_test,int, - distance,int*,int&,std::output_iterator_tag> ostream_iterator_test; -#elif defined(BOOST_MSVC_STD_ITERATOR) -non_pointer_test, - int, void, int*, int&, std::output_iterator_tag> - ostream_iterator_test; -#elif BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006)) -non_pointer_test, - int, long, int*, int&, std::output_iterator_tag> - ostream_iterator_test; -#else -non_pointer_test, - void, void, void, void, std::output_iterator_tag> - ostream_iterator_test; -#endif - - -#ifdef __KCC - typedef long std_list_diff_type; -#else - typedef std::ptrdiff_t std_list_diff_type; -#endif - -non_pointer_test::iterator, int, std_list_diff_type, int*, int&, std::bidirectional_iterator_tag> - list_iterator_test; - -maybe_pointer_test::iterator, int, std::ptrdiff_t, int*, int&, std::random_access_iterator_tag> - vector_iterator_test; - -maybe_pointer_test - int_pointer_test; - -non_pointer_test - my_iterator1_test; - -non_pointer_test - my_iterator2_test; - -non_pointer_test - my_iterator3_test; - -int main() -{ - char chars[100]; - int ints[100]; - - for (int length = 3; length < 100; length += length / 3) - { - std::list l(length); - BOOST_TEST(boost::detail::distance(l.begin(), l.end()) == length); - - std::vector v(length); - BOOST_TEST(boost::detail::distance(v.begin(), v.end()) == length); - - BOOST_TEST(boost::detail::distance(&ints[0], ints + length) == length); - BOOST_TEST(boost::detail::distance(my_iterator1(chars), my_iterator1(chars + length)) == length); - BOOST_TEST(boost::detail::distance(my_iterator2(chars), my_iterator2(chars + length)) == length); - BOOST_TEST(boost::detail::distance(my_iterator3(chars), my_iterator3(chars + length)) == length); - } - return boost::report_errors(); -} diff --git a/test/lvalue_concept_fail.cpp b/test/lvalue_concept_fail.cpp deleted file mode 100644 index 735bb4a..0000000 --- a/test/lvalue_concept_fail.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2004 Jeremy Siek -// 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) - -#include -#include -#include - -int main() -{ - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::readable_iterator_t - , boost::single_pass_traversal_tag - > Iter; - boost::function_requires< - boost_concepts::LvalueIteratorConcept >(); - return boost::exit_success; -} diff --git a/test/permutation_iterator_test.cpp b/test/permutation_iterator_test.cpp deleted file mode 100644 index a62526d..0000000 --- a/test/permutation_iterator_test.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// (C) Copyright Toon Knapen 2001. -// (C) Copyright Roland Richter 2003. -// 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) - -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include - - -// This test checks for convertibility/interoperability among similar -// permutation iterators. We're not using container iterators -// underneath, as in permutation_test, because of bugs in GCC-3.3's -// __normal_iterator that make is_convertible choke when testing -// convertibility. -void iterop_test() -{ - typedef boost::permutation_iterator< double*, int const* > permutation_type; - typedef boost::permutation_iterator< double const*, int const* > permutation_const_type; - - boost::function_requires< - boost_concepts::InteroperableIteratorConcept< - permutation_type - , permutation_const_type - > >(); -} - -void permutation_test() -{ - // Example taken from documentation of old permutation_iterator. - typedef std::vector< double > element_range_type; - typedef std::list< int > index_type; - - const int element_range_size = 10; - const int index_size = 7; - - BOOST_STATIC_ASSERT(index_size <= element_range_size); - element_range_type elements( element_range_size ); - for( element_range_type::iterator el_it = elements.begin(); el_it != elements.end(); ++el_it ) - { *el_it = std::distance(elements.begin(), el_it); } - - index_type indices( index_size ); - for( index_type::iterator i_it = indices.begin(); i_it != indices.end(); ++i_it ) - { *i_it = element_range_size - index_size + std::distance(indices.begin(), i_it); } - std::reverse( indices.begin(), indices.end() ); - - typedef boost::permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type; - permutation_type begin = boost::make_permutation_iterator( elements.begin(), indices.begin() ); - permutation_type it = begin; - permutation_type end = boost::make_permutation_iterator( elements.begin(), indices.end() ); - - BOOST_CHECK( it == begin ); - BOOST_CHECK( it != end ); - - BOOST_CHECK( std::distance( begin, end ) == index_size ); - - for( index_type::iterator i_it1 = indices.begin(); it != end; ++i_it1, ++it ) - { - BOOST_CHECK( *it == elements[ *i_it1 ] ); - } - - it = begin; - for( int i1 = 0; i1 < index_size - 1 ; ++++i1, ++++it ) - { - index_type::iterator i_it2 = indices.begin(); - std::advance( i_it2, i1 ); - BOOST_CHECK( *it == elements[ *i_it2 ] ); - } - - it = begin; - std::advance(it, index_size); - for( index_type::iterator i_it3 = indices.end(); it != begin; ) - { - BOOST_CHECK( *--it == elements[ *--i_it3 ] ); - } - - it = begin; - std::advance(it, index_size); - for( int i2 = 0; i2 < index_size - 1; i2+=2, --it ) - { - index_type::iterator i_it4 = --indices.end(); - std::advance( i_it4, -i2 ); - BOOST_CHECK( *--it == elements[ *i_it4 ] ); - } - -} - - -int test_main(int, char *[]) -{ - permutation_test(); - return 0; -} diff --git a/test/pointee.cpp b/test/pointee.cpp deleted file mode 100755 index b39fce1..0000000 --- a/test/pointee.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright David Abrahams 2004. Use, modification and distribution is -// subject to 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) - -#include -#include -#include "static_assert_same.hpp" -#include -#include - -template -struct proxy_ptr -{ - typedef T element_type; - struct proxy - { - operator Ref() const; - }; - proxy operator*() const; -}; - -template -struct proxy_ref_ptr : proxy_ptr -{ -}; - -template -struct proxy_value_ptr : proxy_ptr -{ - typedef typename boost::add_const::type element_type; -}; - -struct X { - template X(T const&); - template operator T&() const; -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(X) - -int main() -{ - STATIC_ASSERT_SAME(boost::pointee >::type, int); - STATIC_ASSERT_SAME(boost::pointee >::type, X); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee::type, int); - STATIC_ASSERT_SAME(boost::pointee::type, int const); - - STATIC_ASSERT_SAME(boost::pointee::type, X); - STATIC_ASSERT_SAME(boost::pointee::type, X const); - - STATIC_ASSERT_SAME(boost::pointee >::type, int); - STATIC_ASSERT_SAME(boost::pointee >::type, X); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee::iterator >::type, int); - STATIC_ASSERT_SAME(boost::pointee::iterator >::type, X); - - STATIC_ASSERT_SAME(boost::pointee::const_iterator >::type, int const); - STATIC_ASSERT_SAME(boost::pointee::const_iterator >::type, X const); - return 0; -} diff --git a/test/reverse_iterator_test.cpp b/test/reverse_iterator_test.cpp deleted file mode 100644 index 828bdfe..0000000 --- a/test/reverse_iterator_test.cpp +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright Thomas Witt 2003, Jeremy Siek 2004. - -// 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) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using boost::dummyT; - -// Test reverse iterator -int main() -{ - dummyT array[] = { dummyT(0), dummyT(1), dummyT(2), - dummyT(3), dummyT(4), dummyT(5) }; - const int N = sizeof(array)/sizeof(dummyT); - - // Concept checks - // Adapting old-style iterators - { - typedef boost::reverse_iterator > Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::reverse_iterator > Iter; - boost::function_requires< boost::Mutable_BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - // Adapting new-style iterators - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_iterator_t - , boost::bidirectional_traversal_tag - > iter; - typedef boost::reverse_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } -#if 0 - // It does not seem feasible to make this work. Need to change docs to - // require at lease Readable for the base iterator. -Jeremy - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::writable_iterator_t - , boost::bidirectional_traversal_tag - > iter; - typedef boost::reverse_iterator Iter; - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } -#endif -#if !BOOST_WORKAROUND(BOOST_MSVC, == 1200) // Causes Internal Error in linker. - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::bidirectional_traversal_tag - > iter; - typedef boost::reverse_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_lvalue_iterator_t - , boost::bidirectional_traversal_tag - > iter; - typedef boost::reverse_iterator Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::writable_lvalue_iterator_t - , boost::bidirectional_traversal_tag - > iter; - typedef boost::reverse_iterator Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::LvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } -#endif - - // Test reverse_iterator - { - dummyT reversed[N]; - std::copy(array, array + N, reversed); - std::reverse(reversed, reversed + N); - - typedef boost::reverse_iterator reverse_iterator; - - reverse_iterator i(reversed + N); - boost::random_access_iterator_test(i, N, array); - - boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array); - - typedef boost::reverse_iterator const_reverse_iterator; - - const_reverse_iterator j(reversed + N); - boost::random_access_iterator_test(j, N, array); - - const dummyT* const_reversed = reversed; - - boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array); - - boost::const_nonconst_iterator_test(i, ++j); - } - - // Test reverse_iterator again, with traits fully deducible on all platforms - { - std::deque reversed_container; - std::reverse_copy(array, array + N, std::back_inserter(reversed_container)); - const std::deque::iterator reversed = reversed_container.begin(); - - - typedef boost::reverse_iterator< - std::deque::iterator> reverse_iterator; - typedef boost::reverse_iterator< - std::deque::const_iterator> const_reverse_iterator; - - // MSVC/STLport gives an INTERNAL COMPILER ERROR when any computation - // (e.g. "reversed + N") is used in the constructor below. - const std::deque::iterator finish = reversed_container.end(); - reverse_iterator i(finish); - - boost::random_access_iterator_test(i, N, array); - boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array); - - const_reverse_iterator j = reverse_iterator(finish); - boost::random_access_iterator_test(j, N, array); - - const std::deque::const_iterator const_reversed = reversed; - boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array); - - // Many compilers' builtin deque iterators don't interoperate well, though - // STLport fixes that problem. -#if defined(__SGI_STL_PORT) \ - || !BOOST_WORKAROUND(__GNUC__, <= 2) \ - && !(BOOST_WORKAROUND(__GNUC__, == 3) && BOOST_WORKAROUND(__GNUC_MINOR__, <= 1)) \ - && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) \ - && !BOOST_WORKAROUND(__LIBCOMO_VERSION__, BOOST_TESTED_AT(29)) \ - && !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 1) - - boost::const_nonconst_iterator_test(i, ++j); - -#endif - } - - return boost::report_errors(); -} diff --git a/test/static_assert_same.hpp b/test/static_assert_same.hpp deleted file mode 100644 index 6df0506..0000000 --- a/test/static_assert_same.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright David Abrahams 2003. -// 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) -#ifndef STATIC_ASSERT_SAME_DWA2003530_HPP -# define STATIC_ASSERT_SAME_DWA2003530_HPP - -#include -# include - -#define STATIC_ASSERT_SAME( T1,T2 ) BOOST_MPL_ASSERT((::boost::is_same< T1, T2 >)) - -template -struct static_assert_same -{ - BOOST_MPL_ASSERT((::boost::is_same< T1, T2 >)); - enum { value = 1 }; -}; - -#endif // STATIC_ASSERT_SAME_DWA2003530_HPP diff --git a/test/transform_iterator_test.cpp b/test/transform_iterator_test.cpp deleted file mode 100644 index bf08dd2..0000000 --- a/test/transform_iterator_test.cpp +++ /dev/null @@ -1,248 +0,0 @@ -// (C) Copyright Jeremy Siek 2002. -// 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) - -// Revision History -// 22 Nov 2002 Thomas Witt -// Added interoperability check. -// 28 Oct 2002 Jeremy Siek -// Updated for new iterator adaptors. -// 08 Mar 2001 Jeremy Siek -// Moved test of transform iterator into its own file. It to -// to be in iterator_adaptor_test.cpp. - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -namespace boost { namespace detail -{ - template<> struct function_object_result - { - typedef int type; - }; -}} -#endif - -struct mult_functor { - // Functors used with transform_iterator must be - // DefaultConstructible, as the transform_iterator must be - // DefaultConstructible to satisfy the requirements for - // TrivialIterator. - mult_functor() { } - mult_functor(int aa) : a(aa) { } - int operator()(int b) const { return a * b; } - int a; -}; - -struct adaptable_mult_functor - : mult_functor -{ - typedef int result_type; - typedef int argument_type; - // Functors used with transform_iterator must be - // DefaultConstructible, as the transform_iterator must be - // DefaultConstructible to satisfy the requirements for - // TrivialIterator. - adaptable_mult_functor() { } - adaptable_mult_functor(int aa) : mult_functor(aa) { } -}; - - -struct const_select_first -{ - typedef int const& result_type; - - int const& operator()(std::pairconst& p) const - { - return p.first; - } -}; - -struct select_first - : const_select_first // derivation to allow conversions -{ - typedef int& result_type; - - int& operator()(std::pair& p) const - { - return p.first; - } -}; - -struct select_second -{ - typedef int& result_type; - - int& operator()(std::pair& p) const - { - return p.second; - } -}; - -struct value_select_first -{ - typedef int result_type; - - int operator()(std::pairconst& p) const - { - return p.first; - } -}; - -int mult_2(int arg) -{ - return arg*2; -} - - -int -main() -{ - const int N = 10; - - // Concept checks - { - typedef boost::transform_iterator iter_t; - typedef boost::transform_iterator c_iter_t; - - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); - } - - // Test transform_iterator - { - int x[N], y[N]; - for (int k = 0; k < N; ++k) - x[k] = k; - std::copy(x, x + N, y); - - for (int k2 = 0; k2 < N; ++k2) - x[k2] = x[k2] * 2; - - typedef boost::transform_iterator iter_t; - iter_t i(y, adaptable_mult_functor(2)); - boost::input_iterator_test(i, x[0], x[1]); - boost::input_iterator_test(iter_t(&y[0], adaptable_mult_functor(2)), x[0], x[1]); - - boost::random_access_readable_iterator_test(i, N, x); - } - - // Test transform_iterator non adaptable functor - { - int x[N], y[N]; - for (int k = 0; k < N; ++k) - x[k] = k; - std::copy(x, x + N, y); - - for (int k2 = 0; k2 < N; ++k2) - x[k2] = x[k2] * 2; - - typedef boost::transform_iterator iter_t; - iter_t i(y, mult_functor(2)); - boost::input_iterator_test(i, x[0], x[1]); - boost::input_iterator_test(iter_t(&y[0], mult_functor(2)), x[0], x[1]); - - boost::random_access_readable_iterator_test(i, N, x); - } - - // Test transform_iterator default argument handling - { - { - typedef boost::transform_iterator iter_t; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); - } - - { - typedef boost::transform_iterator iter_t; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); - } - - { - typedef boost::transform_iterator iter_t; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); - } - } - - // Test transform_iterator with function pointers - { - int x[N], y[N]; - for (int k = 0; k < N; ++k) - x[k] = k; - std::copy(x, x + N, y); - - for (int k2 = 0; k2 < N; ++k2) - x[k2] = x[k2] * 2; - - boost::input_iterator_test( - boost::make_transform_iterator(y, mult_2), x[0], x[1]); - - boost::input_iterator_test( - boost::make_transform_iterator(&y[0], mult_2), x[0], x[1]); - - boost::random_access_readable_iterator_test( - boost::make_transform_iterator(y, mult_2), N, x); - - } - - // Test transform_iterator as projection iterator - { - typedef std::pair pair_t; - - int x[N]; - int y[N]; - pair_t values[N]; - - for(int i = 0; i < N; ++i) { - - x[i] = i; - y[i] = N - (i + 1); - - } - - std::copy( - x - , x + N - , boost::make_transform_iterator((pair_t*)values, select_first()) - ); - - std::copy( - y - , y + N - , boost::make_transform_iterator((pair_t*)values, select_second()) - ); - - boost::random_access_readable_iterator_test( - boost::make_transform_iterator((pair_t*)values, value_select_first()) - , N - , x - ); - - boost::random_access_readable_iterator_test( - boost::make_transform_iterator((pair_t*)values, const_select_first()) - , N, x - ); - - boost::constant_lvalue_iterator_test( - boost::make_transform_iterator((pair_t*)values, const_select_first()), x[0]); - - boost::non_const_lvalue_iterator_test( - boost::make_transform_iterator((pair_t*)values, select_first()), x[0], 17); - - boost::const_nonconst_iterator_test( - ++boost::make_transform_iterator((pair_t*)values, select_first()) - , boost::make_transform_iterator((pair_t*)values, const_select_first()) - ); - } - - return boost::report_errors(); -} diff --git a/test/unit_tests.cpp b/test/unit_tests.cpp deleted file mode 100644 index 2434310..0000000 --- a/test/unit_tests.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright David Abrahams 2003. -// 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) -#include -#include - -#include "static_assert_same.hpp" - -#include - -#include - -struct X { int a; }; - -BOOST_TT_BROKEN_COMPILER_SPEC(X) - -struct Xiter : boost::iterator_adaptor -{ - Xiter(); - Xiter(X* p) : boost::iterator_adaptor(p) {} -}; - -void take_xptr(X*) {} -void operator_arrow_test() -{ - // check that the operator-> result is a pointer for lvalue iterators - X x; - take_xptr(Xiter(&x).operator->()); -} - -template -struct static_assert_min_cat - : static_assert_same< - typename boost::detail::minimum_category::type, Min - > -{}; - -void category_test() -{ - using namespace boost; - using namespace boost::detail; - - BOOST_STATIC_ASSERT(( - !boost::is_convertible< - std::input_iterator_tag - , input_output_iterator_tag>::value)); - - BOOST_STATIC_ASSERT(( - !boost::is_convertible< - std::output_iterator_tag - , input_output_iterator_tag>::value)); - - BOOST_STATIC_ASSERT(( - boost::is_convertible< - input_output_iterator_tag - , std::input_iterator_tag>::value)); - - BOOST_STATIC_ASSERT(( - boost::is_convertible< - input_output_iterator_tag - , std::output_iterator_tag>::value)); - -#if 0 // This seems wrong; we're not advertising - // input_output_iterator_tag are we? - BOOST_STATIC_ASSERT(( - boost::is_convertible< - std::forward_iterator_tag - , input_output_iterator_tag>::value)); -#endif - - int test = static_assert_min_cat< - std::input_iterator_tag,input_output_iterator_tag, std::input_iterator_tag - >::value; - - test = static_assert_min_cat< - input_output_iterator_tag,std::input_iterator_tag, std::input_iterator_tag - >::value; - -#if 0 - test = static_assert_min_cat< - input_output_iterator_tag,std::forward_iterator_tag, input_output_iterator_tag - >::value; -#endif - - test = static_assert_min_cat< - std::input_iterator_tag,std::forward_iterator_tag, std::input_iterator_tag - >::value; - - test = static_assert_min_cat< - std::input_iterator_tag,std::random_access_iterator_tag, std::input_iterator_tag - >::value; - -#if 0 // This would be wrong: a random access iterator is not - // neccessarily writable, as is an output iterator. - test = static_assert_min_cat< - std::output_iterator_tag,std::random_access_iterator_tag, std::output_iterator_tag - >::value; -#endif - - (void)test; -} - -int main() -{ - category_test(); - operator_arrow_test(); - return 0; -} - diff --git a/test/zip_iterator_test.cpp b/test/zip_iterator_test.cpp deleted file mode 100755 index c6692d2..0000000 --- a/test/zip_iterator_test.cpp +++ /dev/null @@ -1,833 +0,0 @@ -// (C) Copyright Dave Abrahams and Thomas Becker 2003. 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) -// - -// File: -// ===== -// zip_iterator_test_main.cpp - -// Author: -// ======= -// Thomas Becker - -// Created: -// ======== -// Jul 15, 2003 - -// Purpose: -// ======== -// Test driver for zip_iterator.hpp - -// Compilers Tested: -// ================= -// Metrowerks Codewarrior Pro 7.2, 8.3 -// gcc 2.95.3 -// gcc 3.2 -// Microsoft VC 6sp5 (test fails due to some compiler bug) -// Microsoft VC 7 (works) -// Microsoft VC 7.1 -// Intel 5 -// Intel 6 -// Intel 7.1 -// Intel 8 -// Borland 5.5.1 (broken due to lack of support from Boost.Tuples) - -///////////////////////////////////////////////////////////////////////////// -// -// Includes -// -///////////////////////////////////////////////////////////////////////////// - -#include -#include // 2nd #include tests #include guard. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -template -struct pure_traversal - : boost::detail::pure_traversal_tag< - typename boost::iterator_traversal::type - > -{}; - -///////////////////////////////////////////////////////////////////////////// -// -// Das Main Funktion -// -///////////////////////////////////////////////////////////////////////////// - -int main( void ) -{ - - std::cout << "\n" - << "***********************************************\n" - << "* *\n" - << "* Test driver for boost::zip_iterator *\n" - << "* Copyright Thomas Becker 2003 *\n" - << "* *\n" - << "***********************************************\n\n" - << std::flush; - - size_t num_successful_tests = 0; - size_t num_failed_tests = 0; - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator construction and dereferencing - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator construction and dereferencing: " - << std::flush; - - std::vector vect1(3); - vect1[0] = 42.; - vect1[1] = 43.; - vect1[2] = 44.; - - std::set intset; - intset.insert(52); - intset.insert(53); - intset.insert(54); - // - - typedef - boost::zip_iterator< - boost::tuples::tuple< - std::set::iterator - , std::vector::iterator - > - > zit_mixed; - - zit_mixed zip_it_mixed = zit_mixed( - boost::make_tuple( - intset.begin() - , vect1.begin() - ) - ); - - boost::tuples::tuple val_tuple( - *zip_it_mixed); - - boost::tuples::tuple ref_tuple( - *zip_it_mixed); - - double dblOldVal = boost::tuples::get<1>(ref_tuple); - boost::tuples::get<1>(ref_tuple) -= 41.; - - if( 52 == boost::tuples::get<0>(val_tuple) && - 42. == boost::tuples::get<1>(val_tuple) && - 52 == boost::tuples::get<0>(ref_tuple) && - 1. == boost::tuples::get<1>(ref_tuple) && - 1. == *vect1.begin() - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - // Undo change to vect1 - boost::tuples::get<1>(ref_tuple) = dblOldVal; - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator with 12 components - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterators with 12 components: " - << std::flush; - - // Declare 12 containers - // - std::list li1; - li1.push_back(1); - std::set se1; - se1.insert(2); - std::vector ve1; - ve1.push_back(3); - // - std::list li2; - li2.push_back(4); - std::set se2; - se2.insert(5); - std::vector ve2; - ve2.push_back(6); - // - std::list li3; - li3.push_back(7); - std::set se3; - se3.insert(8); - std::vector ve3; - ve3.push_back(9); - // - std::list li4; - li4.push_back(10); - std::set se4; - se4.insert(11); - std::vector ve4; - ve4.push_back(12); - - // typedefs for cons lists of iterators. - typedef boost::tuples::cons< - std::set::iterator, - boost::tuples::tuple< - std::vector::iterator, - std::list::iterator, - std::set::iterator, - std::vector::iterator, - std::list::iterator, - std::set::iterator, - std::vector::iterator, - std::list::iterator, - std::set::iterator, - std::vector::const_iterator - >::inherited - > cons_11_its_type; - // - typedef boost::tuples::cons< - std::list::const_iterator, - cons_11_its_type - > cons_12_its_type; - - // typedefs for cons lists for dereferencing the zip iterator - // made from the cons list above. - typedef boost::tuples::cons< - const int&, - boost::tuples::tuple< - int&, - int&, - const int&, - int&, - int&, - const int&, - int&, - int&, - const int&, - const int& - >::inherited - > cons_11_refs_type; - // - typedef boost::tuples::cons< - const int&, - cons_11_refs_type - > cons_12_refs_type; - - // typedef for zip iterator with 12 elements - typedef boost::zip_iterator zip_it_12_type; - - // Declare a 12-element zip iterator. - zip_it_12_type zip_it_12( - cons_12_its_type( - li1.begin(), - cons_11_its_type( - se1.begin(), - boost::make_tuple( - ve1.begin(), - li2.begin(), - se2.begin(), - ve2.begin(), - li3.begin(), - se3.begin(), - ve3.begin(), - li4.begin(), - se4.begin(), - ve4.begin() - ) - ) - ) - ); - - // Dereference, mess with the result a little. - cons_12_refs_type zip_it_12_dereferenced(*zip_it_12); - boost::tuples::get<9>(zip_it_12_dereferenced) = 42; - - // Make a copy and move it a little to force some instantiations. - zip_it_12_type zip_it_12_copy(zip_it_12); - ++zip_it_12_copy; - - if( boost::tuples::get<11>(zip_it_12.get_iterator_tuple()) == ve4.begin() && - boost::tuples::get<11>(zip_it_12_copy.get_iterator_tuple()) == ve4.end() && - 1 == boost::tuples::get<0>(zip_it_12_dereferenced) && - 12 == boost::tuples::get<11>(zip_it_12_dereferenced) && - 42 == *(li4.begin()) - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator incrementing and dereferencing - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator ++ and *: " - << std::flush; - - std::vector vect2(3); - vect2[0] = 2.2; - vect2[1] = 3.3; - vect2[2] = 4.4; - - boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > - > - zip_it_begin( - boost::make_tuple( - vect1.begin(), - vect2.begin() - ) - ); - - boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > - > - zip_it_run( - boost::make_tuple( - vect1.begin(), - vect2.begin() - ) - ); - - boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > - > - zip_it_end( - boost::make_tuple( - vect1.end(), - vect2.end() - ) - ); - - if( zip_it_run == zip_it_begin && - 42. == boost::tuples::get<0>(*zip_it_run) && - 2.2 == boost::tuples::get<1>(*zip_it_run) && - 43. == boost::tuples::get<0>(*(++zip_it_run)) && - 3.3 == boost::tuples::get<1>(*zip_it_run) && - 44. == boost::tuples::get<0>(*(++zip_it_run)) && - 4.4 == boost::tuples::get<1>(*zip_it_run) && - zip_it_end == ++zip_it_run - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator decrementing and dereferencing - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator -- and *: " - << std::flush; - - if( zip_it_run == zip_it_end && - zip_it_end == zip_it_run-- && - 44. == boost::tuples::get<0>(*zip_it_run) && - 4.4 == boost::tuples::get<1>(*zip_it_run) && - 43. == boost::tuples::get<0>(*(--zip_it_run)) && - 3.3 == boost::tuples::get<1>(*zip_it_run) && - 42. == boost::tuples::get<0>(*(--zip_it_run)) && - 2.2 == boost::tuples::get<1>(*zip_it_run) && - zip_it_begin == zip_it_run - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator copy construction and equality - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator copy construction and equality: " - << std::flush; - - boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > - > zip_it_run_copy(zip_it_run); - - if(zip_it_run == zip_it_run && zip_it_run == zip_it_run_copy) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator inequality - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator inequality: " - << std::flush; - - if(!(zip_it_run != zip_it_run_copy) && zip_it_run != ++zip_it_run_copy) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator less than - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator less than: " - << std::flush; - - // Note: zip_it_run_copy == zip_it_run + 1 - // - if( zip_it_run < zip_it_run_copy && - !( zip_it_run < --zip_it_run_copy) && - zip_it_run == zip_it_run_copy - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator less than or equal - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "zip iterator less than or equal: " - << std::flush; - - // Note: zip_it_run_copy == zip_it_run - // - ++zip_it_run; - zip_it_run_copy += 2; - - if( zip_it_run <= zip_it_run_copy && - zip_it_run <= --zip_it_run_copy && - !( zip_it_run <= --zip_it_run_copy) && - zip_it_run <= zip_it_run - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator greater than - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator greater than: " - << std::flush; - - // Note: zip_it_run_copy == zip_it_run - 1 - // - if( zip_it_run > zip_it_run_copy && - !( zip_it_run > ++zip_it_run_copy) && - zip_it_run == zip_it_run_copy - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator greater than or equal - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator greater than or equal: " - << std::flush; - - ++zip_it_run; - - // Note: zip_it_run == zip_it_run_copy + 1 - // - if( zip_it_run >= zip_it_run_copy && - --zip_it_run >= zip_it_run_copy && - ! (zip_it_run >= ++zip_it_run_copy) - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator + int - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator + int: " - << std::flush; - - // Note: zip_it_run == zip_it_run_copy - 1 - // - zip_it_run = zip_it_run + 2; - ++zip_it_run_copy; - - if( zip_it_run == zip_it_run_copy && zip_it_run == zip_it_begin + 3 ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator - int - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator - int: " - << std::flush; - - // Note: zip_it_run == zip_it_run_copy, and both are at end position - // - zip_it_run = zip_it_run - 2; - --zip_it_run_copy; - --zip_it_run_copy; - - if( zip_it_run == zip_it_run_copy && (zip_it_run - 1) == zip_it_begin ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator += - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator +=: " - << std::flush; - - // Note: zip_it_run == zip_it_run_copy, and both are at begin + 1 - // - zip_it_run += 2; - if( zip_it_run == zip_it_begin + 3 ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator -= - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator -=: " - << std::flush; - - // Note: zip_it_run is at end position, zip_it_run_copy is at - // begin plus one. - // - zip_it_run -= 2; - if( zip_it_run == zip_it_run_copy ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator getting member iterators - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator member iterators: " - << std::flush; - - // Note: zip_it_run and zip_it_run_copy are both at - // begin plus one. - // - if( boost::tuples::get<0>(zip_it_run.get_iterator_tuple()) == vect1.begin() + 1 && - boost::tuples::get<1>(zip_it_run.get_iterator_tuple()) == vect2.begin() + 1 - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Making zip iterators - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Making zip iterators: " - << std::flush; - - std::vector > - vect_of_tuples(3); - - std::copy( - boost::make_zip_iterator( - boost::make_tuple( - vect1.begin(), - vect2.begin() - ) - ), - boost::make_zip_iterator( - boost::make_tuple( - vect1.end(), - vect2.end() - ) - ), - vect_of_tuples.begin() - ); - - if( 42. == boost::tuples::get<0>(*vect_of_tuples.begin()) && - 2.2 == boost::tuples::get<1>(*vect_of_tuples.begin()) && - 43. == boost::tuples::get<0>(*(vect_of_tuples.begin() + 1)) && - 3.3 == boost::tuples::get<1>(*(vect_of_tuples.begin() + 1)) && - 44. == boost::tuples::get<0>(*(vect_of_tuples.begin() + 2)) && - 4.4 == boost::tuples::get<1>(*(vect_of_tuples.begin() + 2)) - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator non-const --> const conversion - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator non-const to const conversion: " - << std::flush; - - boost::zip_iterator< - boost::tuples::tuple< - std::set::const_iterator, - std::vector::const_iterator - > - > - zip_it_const( - boost::make_tuple( - intset.begin(), - vect2.begin() - ) - ); - // - boost::zip_iterator< - boost::tuples::tuple< - std::set::iterator, - std::vector::const_iterator - > - > - zip_it_half_const( - boost::make_tuple( - intset.begin(), - vect2.begin() - ) - ); - // - boost::zip_iterator< - boost::tuples::tuple< - std::set::iterator, - std::vector::iterator - > - > - zip_it_non_const( - boost::make_tuple( - intset.begin(), - vect2.begin() - ) - ); - - zip_it_half_const = ++zip_it_non_const; - zip_it_const = zip_it_half_const; - ++zip_it_const; -// zip_it_non_const = ++zip_it_const; // Error: can't convert from const to non-const - - if( 54 == boost::tuples::get<0>(*zip_it_const) && - 4.4 == boost::tuples::get<1>(*zip_it_const) && - 53 == boost::tuples::get<0>(*zip_it_half_const) && - 3.3 == boost::tuples::get<1>(*zip_it_half_const) - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - - ///////////////////////////////////////////////////////////////////////////// - // - // Zip iterator categories - // - ///////////////////////////////////////////////////////////////////////////// - - std::cout << "Zip iterator categories: " - << std::flush; - - // The big iterator of the previous test has vector, list, and set iterators. - // Therefore, it must be bidirectional, but not random access. - bool bBigItIsBidirectionalIterator = boost::is_convertible< - boost::iterator_traversal::type - , boost::bidirectional_traversal_tag - >::value; - - bool bBigItIsRandomAccessIterator = boost::is_convertible< - boost::iterator_traversal::type - , boost::random_access_traversal_tag - >::value; - - // A combining iterator with all vector iterators must have random access - // traversal. - // - typedef boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > - > all_vects_type; - - bool bAllVectsIsRandomAccessIterator = boost::is_convertible< - boost::iterator_traversal::type - , boost::random_access_traversal_tag - >::value; - - // The big test. - if( bBigItIsBidirectionalIterator && - ! bBigItIsRandomAccessIterator && - bAllVectsIsRandomAccessIterator - ) - { - ++num_successful_tests; - std::cout << "OK" << std::endl; - } - else - { - ++num_failed_tests = 0; - std::cout << "not OK" << std::endl; - } - - // Done - // - std::cout << "\nTest Result:" - << "\n============" - << "\nNumber of successful tests: " << static_cast(num_successful_tests) - << "\nNumber of failed tests: " << static_cast(num_failed_tests) - << std::endl; - - return num_failed_tests; -} -