diff --git a/doc/filter_iterator_ref.rst b/doc/filter_iterator_ref.rst index d1f363e..5321053 100644 --- a/doc/filter_iterator_ref.rst +++ b/doc/filter_iterator_ref.rst @@ -151,4 +151,4 @@ operations. :Effects: Increments ``*this`` and then continues to increment ``*this`` until either ``this->base() == this->end()`` or ``f(**this) == true``. - \ No newline at end of file +:Returns: ``*this`` \ No newline at end of file diff --git a/doc/transform_iterator.html b/doc/transform_iterator.html index 9afeef0..77d6574 100644 --- a/doc/transform_iterator.html +++ b/doc/transform_iterator.html @@ -49,8 +49,9 @@ then returns the result.

Table of Contents

@@ -60,9 +61,7 @@ template <class UnaryFunction, class Reference = use_default, class Value = use_default> class transform_iterator - : public iterator_adaptor</* see discussion */> { - friend class iterator_core_access; public: transform_iterator(); transform_iterator(Iterator const& x, UnaryFunction f); @@ -74,10 +73,13 @@ public: , typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition ); + reference operator*() const; + transform_iterator& operator++(); + Iterator base() const; UnaryFunction functor() const; private: - typename transform_iterator::value_type dereference() const; - UnaryFunction m_f; + Iterator m_iterator; // exposition + UnaryFunction m_f; // exposition };
@@ -87,8 +89,11 @@ the expression f(*i) must be v 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 type Iterator must at least model Readable Iterator. The -resulting transform_iterator models the most refined of the +

The type Iterator must at least model Readable Iterator.

+
+
+

transform_iterator models

+

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

-
-

transform_iterator public operations

+
+

transform_iterator operations

transform_iterator();

@@ -143,6 +148,15 @@ transform_iterator(
+

Iterator base() const;

+ +++ + + + +
Returns:m_iterator

UnaryFunction functor() const;

@@ -152,19 +166,90 @@ transform_iterator(
-
-
-

transform_iterator private operations

-

typename transform_iterator::value_type dereference() const;

+

reference operator*() const;

- + + + +
Returns:m_f(transform_iterator::dereference());
Returns:m_f(*m_iterator)
+

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 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
+
+
diff --git a/doc/transform_iterator.rst b/doc/transform_iterator.rst index 021532d..8e39d07 100644 --- a/doc/transform_iterator.rst +++ b/doc/transform_iterator.rst @@ -21,3 +21,5 @@ .. contents:: Table of Contents .. include:: transform_iterator_ref.rst +.. include:: make_transform_iterator.rst +.. include:: transform_iterator_eg.rst diff --git a/doc/transform_iterator_ref.rst b/doc/transform_iterator_ref.rst index 40eaaad..08a52ef 100644 --- a/doc/transform_iterator_ref.rst +++ b/doc/transform_iterator_ref.rst @@ -7,9 +7,7 @@ class Reference = use_default, class Value = use_default> class transform_iterator - : public iterator_adaptor { - friend class iterator_core_access; public: transform_iterator(); transform_iterator(Iterator const& x, UnaryFunction f); @@ -21,15 +19,18 @@ , typename enable_if_convertible::type* = 0 // exposition ); + reference operator*() const; + transform_iterator& operator++(); + Iterator base() const; UnaryFunction functor() const; private: - typename transform_iterator::value_type dereference() const; - UnaryFunction m_f; + Iterator m_iterator; // exposition + UnaryFunction m_f; // exposition }; ``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 @@ -37,8 +38,13 @@ type ``UnaryFunction``, ``i`` is an object of type ``Iterator``, and where the type of ``f(*i)`` must be ``result_of::reference)>::type``. -The type ``Iterator`` must at least model Readable Iterator. The -resulting ``transform_iterator`` models the most refined of the +The type ``Iterator`` must at least model Readable Iterator. + + +``transform_iterator`` models +----------------------------- + +The resulting ``transform_iterator`` models the most refined of the following options that is also modeled by ``Iterator``. * Writable Lvalue Iterator if ``result_of::reference)>::type`` is a non-const reference. @@ -56,9 +62,9 @@ The ``reference`` type of ``transform_iterator`` is ``result_of::reference)>::type``. The ``value_type`` is ``remove_cv >::type``. -``transform_iterator`` public operations -........................................ +``transform_iterator`` operations +--------------------------------- ``transform_iterator();`` @@ -83,14 +89,24 @@ The ``value_type`` is ``remove_cv >::type``. :Returns: An instance of ``transform_iterator`` that is a copy of ``t``. :Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. + +``Iterator base() const;`` + +:Returns: ``m_iterator`` + + ``UnaryFunction functor() const;`` :Returns: ``m_f`` -``transform_iterator`` private operations -......................................... -``typename transform_iterator::value_type dereference() const;`` +``reference operator*() const;`` -:Returns: ``m_f(transform_iterator::dereference());`` +:Returns: ``m_f(*m_iterator)`` + + +``transform_iterator& operator++();`` + +:Effects: ``++m_iterator`` +:Returns: ``*this``