Index: boost/iterator/function_input_iterator.hpp =================================================================== --- boost/iterator/function_input_iterator.hpp (revision 80259) +++ boost/iterator/function_input_iterator.hpp (working copy) @@ -1,4 +1,5 @@ // Copyright 2009 (C) Dean Michael Berris +// Copyright 2012 (C) Google, Inc. // 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) @@ -29,7 +30,7 @@ public: function_input_iterator() {} function_input_iterator(Function & f_, Input state_ = Input()) - : f(&f_), state(state_), value((*f)()) {} + : first(true), f(&f_), state(state_), value() {} void increment() { value = (*f)(); @@ -38,6 +39,10 @@ typename Function::result_type const & dereference() const { + if (first) { + value = (*f)(); + first = false; + } return value; } @@ -46,9 +51,10 @@ } private: + mutable bool first; Function * f; Input state; - typename Function::result_type value; + mutable typename Function::result_type value; }; template @@ -63,8 +69,7 @@ public: function_pointer_input_iterator() {} function_pointer_input_iterator(Function &f_, Input state_ = Input()) - : f(f_), state(state_), value((*f)()) - {} + : first(true), f(f_), state(state_), value() {} void increment() { value = (*f)(); @@ -73,6 +78,10 @@ typename function_types::result_type::type const & dereference() const { + if (first) { + value = (*f)(); + first = false; + } return value; } @@ -81,9 +90,10 @@ } private: + mutable bool first; Function f; Input state; - typename function_types::result_type::type value; + mutable typename function_types::result_type::type value; }; template Index: libs/iterator/doc/function_input_iterator.rst =================================================================== --- libs/iterator/doc/function_input_iterator.rst (revision 80259) +++ libs/iterator/doc/function_input_iterator.rst (working copy) @@ -1,10 +1,13 @@ :Author: - `Dean Michael Berris `_ + `Dean Michael Berris `_ :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 ======================= @@ -112,7 +115,7 @@ copy( make_function_input_iterator(f,infinite()), make_function_input_iterator(f,infinite()), - ostream_iterator(count, " ") + ostream_iterator(cout, " ") ); Above, instead of creating a huge vector we rely on the STL copy algorithm