$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r80568 - in branches/release: boost/iterator libs/iterator libs/iterator/doc libs/iterator/test
From: jeffrey.hellrung_at_[hidden]
Date: 2012-09-17 22:50:53
Author: jeffrey.hellrung
Date: 2012-09-17 22:50:52 EDT (Mon, 17 Sep 2012)
New Revision: 80568
URL: http://svn.boost.org/trac/boost/changeset/80568
Log:
Merging boost/iterator and libs/iterator trunk to release.
Properties modified: 
   branches/release/boost/iterator/   (props changed)
   branches/release/libs/iterator/   (props changed)
Text files modified: 
   branches/release/boost/iterator/function_input_iterator.hpp          |    24 +++++++++++++++---------                
   branches/release/boost/iterator/reverse_iterator.hpp                 |     2 +-                                      
   branches/release/libs/iterator/doc/function_input_iterator.rst       |    22 ++++++++++++++--------                  
   branches/release/libs/iterator/test/function_input_iterator_test.cpp |    37 ++++++++++++++++++++++++++++++++++---   
   4 files changed, 64 insertions(+), 21 deletions(-)
Modified: branches/release/boost/iterator/function_input_iterator.hpp
==============================================================================
--- branches/release/boost/iterator/function_input_iterator.hpp	(original)
+++ branches/release/boost/iterator/function_input_iterator.hpp	2012-09-17 22:50:52 EDT (Mon, 17 Sep 2012)
@@ -1,4 +1,6 @@
 // Copyright 2009 (C) Dean Michael Berris <me_at_[hidden]>
+// Copyright 2012 (C) Google, Inc.
+// Copyright 2012 (C) Jeffrey Lee Hellrung, Jr.
 // 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)
@@ -7,11 +9,14 @@
 #ifndef BOOST_FUNCTION_INPUT_ITERATOR
 #define BOOST_FUNCTION_INPUT_ITERATOR
 
+#include <boost/assert.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/function_types/is_function_pointer.hpp>
 #include <boost/function_types/is_function_reference.hpp>
 #include <boost/function_types/result_type.hpp>
 #include <boost/iterator/iterator_facade.hpp>
+#include <boost/none.hpp>
+#include <boost/optional/optional.hpp>
 
 namespace boost {
 
@@ -29,16 +34,17 @@
         public:
             function_input_iterator() {}
             function_input_iterator(Function & f_, Input state_ = Input()) 
-                : f(&f_), state(state_), value((*f)()) {}
+                : f(&f_), state(state_) {}
 
             void increment() {
-                value = (*f)();
+                BOOST_ASSERT(value);
+                value = none;
                 ++state;
             }
 
             typename Function::result_type const & 
                 dereference() const {
-                    return value;
+                    return (value ? value : value = (*f)()).get();
             }
 
             bool equal(function_input_iterator const & other) const {
@@ -48,7 +54,7 @@
         private:
             Function * f;
             Input state;
-            typename Function::result_type value;
+            mutable optional<typename Function::result_type> value;
         };
 
         template <class Function, class Input>
@@ -63,17 +69,17 @@
         public:
             function_pointer_input_iterator() {}
             function_pointer_input_iterator(Function &f_, Input state_ = Input())
-                : f(f_), state(state_), value((*f)()) 
-            {}
+                : f(f_), state(state_) {}
 
             void increment() {
-                value = (*f)();
+                BOOST_ASSERT(value);
+                value = none;
                 ++state;
             }
 
             typename function_types::result_type<Function>::type const &
                 dereference() const {
-                    return value;
+                    return (value ? value : value = (*f)()).get();
             }
 
             bool equal(function_pointer_input_iterator const & other) const {
@@ -83,7 +89,7 @@
         private:
             Function f;
             Input state;
-            typename function_types::result_type<Function>::type value;
+            mutable optional<typename function_types::result_type<Function>::type> value;
         };
 
         template <class Function, class Input>
Modified: branches/release/boost/iterator/reverse_iterator.hpp
==============================================================================
--- branches/release/boost/iterator/reverse_iterator.hpp	(original)
+++ branches/release/boost/iterator/reverse_iterator.hpp	2012-09-17 22:50:52 EDT (Mon, 17 Sep 2012)
@@ -7,8 +7,8 @@
 #ifndef BOOST_REVERSE_ITERATOR_23022003THW_HPP
 #define BOOST_REVERSE_ITERATOR_23022003THW_HPP
 
+#include <boost/next_prior.hpp>
 #include <boost/iterator.hpp>
-#include <boost/utility.hpp>
 #include <boost/iterator/iterator_adaptor.hpp>
 
 namespace boost
Modified: branches/release/libs/iterator/doc/function_input_iterator.rst
==============================================================================
--- branches/release/libs/iterator/doc/function_input_iterator.rst	(original)
+++ branches/release/libs/iterator/doc/function_input_iterator.rst	2012-09-17 22:50:52 EDT (Mon, 17 Sep 2012)
@@ -1,10 +1,13 @@
 :Author:
-    `Dean Michael Berris <mailto:mikhailberis_at_[hidden]>`_
+    `Dean Michael Berris <mailto:me_at_[hidden]>`_
 
 :License:
     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)
 
+:Copyright:
+    Copyright 2012 Google, Inc.
+
 Function Input Iterator
 =======================
 
@@ -15,11 +18,14 @@
 
 .. _InputIterator: http://www.sgi.com/tech/stl/InputIterator.html
 
-Like the Generator Iterator, the Function Input Iterator takes a function
-that models the Generator_ concept (which is basically a nullary or 0-arity
-function object). Each increment of the function Function Input Iterator
-invokes the generator function and stores the value in the iterator. When
-the iterator is dereferenced the stored value is returned.
+The Function Input Iterator takes a function that models the Generator_ concept
+(which is basically a nullary or 0-arity function object). The first dereference
+of the iterator at a given position invokes the generator function and stores
+and returns the result; subsequent dereferences at the same position simply
+return the same stored result. Incrementing the iterator places it at a new
+position, hence a subsequent dereference will generate a new value via another
+invokation of the generator function. This ensures the generator function is
+invoked precisely when the iterator is requested to return a (new) value.
 
 .. _Generator: http://www.sgi.com/tech/stl/Generator.html
 
@@ -58,7 +64,7 @@
 
         template <class Function, class State>
         typename function_input_iterator<Function, State>
-        make_function_input_iterator(Function & f);
+        make_function_input_iterator(Function & f, State s);
 
         struct infinite;
     }
@@ -112,7 +118,7 @@
     copy(
             make_function_input_iterator(f,infinite()),
             make_function_input_iterator(f,infinite()),
-            ostream_iterator<int>(count, " ")
+            ostream_iterator<int>(cout, " ")
         );
    
 Above, instead of creating a huge vector we rely on the STL copy algorithm
Modified: branches/release/libs/iterator/test/function_input_iterator_test.cpp
==============================================================================
--- branches/release/libs/iterator/test/function_input_iterator_test.cpp	(original)
+++ branches/release/libs/iterator/test/function_input_iterator_test.cpp	2012-09-17 22:50:52 EDT (Mon, 17 Sep 2012)
@@ -3,12 +3,17 @@
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include <boost/iterator/function_input_iterator.hpp>
-#include <vector>
-#include <iterator>
 #include <cassert>
+#include <cstddef>
+
 #include <algorithm>
 #include <iostream>
+#include <iterator>
+#include <vector>
+
+#include <boost/iterator/function_input_iterator.hpp>
+
+namespace {
 
 struct ones {
     typedef int result_type;
@@ -21,6 +26,17 @@
     return 1;
 }
 
+struct counter {
+    typedef int result_type;
+    int n;
+    explicit counter(int n_) : n(n_) { }
+    result_type operator() () {
+        return n++;
+    }
+};
+
+} // namespace
+
 using namespace std;
 
 int main(int argc, char * argv[])
@@ -65,6 +81,21 @@
     assert(equal(values.begin(), values.end(), generated.begin()));
     cout << "function iterator test with reference to function successful." << endl;
 
+    // test the iterator with a stateful function object
+    counter counter_generator(42);
+    vector<int>().swap(generated);
+    copy(
+        boost::make_function_input_iterator(counter_generator, 0),
+        boost::make_function_input_iterator(counter_generator, 10),
+        back_inserter(generated)
+        );
+
+    assert(generated.size() == 10);
+    assert(counter_generator.n == 42 + 10);
+    for(std::size_t i = 0; i != 10; ++i)
+        assert(generated[i] == 42 + i);
+    cout << "function iterator test with stateful function object successful." << endl;
+
     return 0;
 }