diff --git a/doc/counting_iterator.html b/doc/counting_iterator.html index 15fc046..cba8045 100644 --- a/doc/counting_iterator.html +++ b/doc/counting_iterator.html @@ -3,204 +3,13 @@ - + Counting Iterator - +
@@ -231,45 +40,32 @@ Railway Operation and Construction -

The counting iterator adaptor implements dereference by returning a -reference to the base object. The other operations are implemented by -the base m_iterator, as per the inheritance from -iterator_adaptor.

+

counting_iterator adapts an arithmetic type, such as int, by +adding an operator* that returns the current value of the object.

Table of Contents

 template <
     class Incrementable
-  , unsigned Access = use_default_access
-  , class Traversal = use_default
+  , class CategoryOrTraversal = use_default
   , class Difference = use_default
 >
 class counting_iterator
-  : public iterator_adaptor<
-        counting_iterator<Incrementable, Access, Traversal, Difference>
-      , Incrementable
-      , Incrementable
-      , Access
-      , /* see details for traversal category */
-      , Incrementable const&
-      , Incrementable const*
-      , /* distance = Difference or a signed integral type */>
 {
-    friend class iterator_core_access;
  public:
     counting_iterator();
     counting_iterator(counting_iterator const& rhs);
-    counting_iterator(Incrementable x);
+    explicit counting_iterator(Incrementable x);
+    Incrementable base() const;
  private:
-    typename counting_iterator::reference dereference() const
-    {
-        return this->base_reference();
-    }
+    Incrementable current; // exposition
   };
 
@@ -281,8 +77,11 @@ the cases when the Incrementablecounting_iterator requirements

The Incrementable type must be Default Constructible, Copy Constructible, and Assignable. The default distance is -an implementation defined signed integegral type.

-

The resulting counting_iterator models Readable Lvalue Iterator.

+an implementation defined signed integral type.

+
+
+

counting_iterator models

+

counting_iterator models Readable Lvalue Iterator.

Furthermore, if you wish to create a counting iterator that is a Forward Traversal Iterator, then the following expressions must be valid:

@@ -306,7 +105,7 @@ i < j
 
-

counting_iterator operations

+

counting_iterator operations

counting_iterator();

@@ -325,23 +124,90 @@ i < j
-

counting_iterator(Incrementable x);

+

explicit counting_iterator(Incrementable x);

- + + + +
Returns:An instance of counting_iterator with its base -object copy constructed from x.
Returns:An instance of counting_iterator with current +constructed from x.
+

reference operator*() const;

+ +++ + + + +
Returns:current
+

counting_iterator& operator++();

+ +++ + + + +
Effects:++current
+

Incrementable base() const;

+ +++ + + + +
Returns:current
+
+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 
+
- - diff --git a/doc/counting_iterator.rst b/doc/counting_iterator.rst index 25fb3b3..52b38da 100644 --- a/doc/counting_iterator.rst +++ b/doc/counting_iterator.rst @@ -21,3 +21,6 @@ .. contents:: Table of Contents .. include:: counting_iterator_ref.rst +.. include:: make_counting_iterator.rst + +.. include:: counting_iterator_eg.rst diff --git a/doc/counting_iterator_abstract.rst b/doc/counting_iterator_abstract.rst index 2ac2233..30f9986 100644 --- a/doc/counting_iterator_abstract.rst +++ b/doc/counting_iterator_abstract.rst @@ -1,5 +1,2 @@ -The counting iterator adaptor implements dereference by returning a -reference to the base object. The other operations are implemented by -the base ``m_iterator``, as per the inheritance from -``iterator_adaptor``. - +``counting_iterator`` adapts an arithmetic type, such as ``int``, by +adding an ``operator*`` that returns the current value of the object. diff --git a/doc/counting_iterator_eg.rst b/doc/counting_iterator_eg.rst new file mode 100644 index 0000000..98d27ec --- /dev/null +++ b/doc/counting_iterator_eg.rst @@ -0,0 +1,35 @@ + +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 diff --git a/doc/counting_iterator_ref.rst b/doc/counting_iterator_ref.rst index f443682..42d283a 100644 --- a/doc/counting_iterator_ref.rst +++ b/doc/counting_iterator_ref.rst @@ -2,31 +2,18 @@ template < class Incrementable - , unsigned Access = use_default_access - , class Traversal = use_default + , class CategoryOrTraversal = use_default , class Difference = use_default > class counting_iterator - : public iterator_adaptor< - counting_iterator - , Incrementable - , Incrementable - , Access - , /* see details for traversal category */ - , Incrementable const& - , Incrementable const* - , /* distance = Difference or a signed integral type */> { - friend class iterator_core_access; public: counting_iterator(); counting_iterator(counting_iterator const& rhs); - counting_iterator(Incrementable x); + explicit counting_iterator(Incrementable x); + Incrementable base() const; private: - typename counting_iterator::reference dereference() const - { - return this->base_reference(); - } + Incrementable current; // exposition }; @@ -39,28 +26,29 @@ The ``Incrementable`` type must be Default Constructible, Copy Constructible, and Assignable. The default distance is -an implementation defined signed integegral type. +an implementation defined signed integral type. -The resulting ``counting_iterator`` models Readable Lvalue Iterator. + +``counting_iterator`` models +---------------------------- + +``counting_iterator`` models Readable Lvalue Iterator. Furthermore, if you wish to create a counting iterator that is a Forward -Traversal Iterator, then the following expressions must be valid: -:: +Traversal Iterator, then the following expressions must be valid:: Incrementable i, j; ++i // pre-increment i == j // operator equal If you wish to create a counting iterator that is a -Bidirectional Traversal Iterator, then pre-decrement is also required: -:: +Bidirectional Traversal Iterator, then pre-decrement is also required:: --i If you wish to create a counting iterator that is a Random Access Traversal Iterator, then these additional expressions are also -required: -:: +required:: counting_iterator::difference_type n; i += n @@ -84,8 +72,22 @@ required: -``counting_iterator(Incrementable x);`` +``explicit counting_iterator(Incrementable x);`` -:Returns: An instance of ``counting_iterator`` with its base - object copy constructed from ``x``. +:Returns: An instance of ``counting_iterator`` with ``current`` + constructed from ``x``. + +``reference operator*() const;`` + +:Returns: ``current`` + + +``counting_iterator& operator++();`` + +:Effects: ``++current`` + + +``Incrementable base() const;`` + +:Returns: ``current`` \ No newline at end of file