Ticket #5825: boost-5825.patch
File boost-5825.patch, 3.4 KB (added by , 10 years ago) |
---|
-
boost/iterator/function_input_iterator.hpp
1 1 // Copyright 2009 (C) Dean Michael Berris <me@deanberris.com> 2 // Copyright 2012 (C) Google, Inc. 2 3 // Distributed under the Boost Software License, Version 1.0. (See 3 4 // accompanying file LICENSE_1_0.txt or copy at 4 5 // http://www.boost.org/LICENSE_1_0.txt) … … 29 30 public: 30 31 function_input_iterator() {} 31 32 function_input_iterator(Function & f_, Input state_ = Input()) 32 : f (&f_), state(state_), value((*f)()) {}33 : first(true), f(&f_), state(state_), value() {} 33 34 34 35 void increment() { 35 36 value = (*f)(); … … 38 39 39 40 typename Function::result_type const & 40 41 dereference() const { 42 if (first) { 43 value = (*f)(); 44 first = false; 45 } 41 46 return value; 42 47 } 43 48 … … 46 51 } 47 52 48 53 private: 54 mutable bool first; 49 55 Function * f; 50 56 Input state; 51 typename Function::result_type value;57 mutable typename Function::result_type value; 52 58 }; 53 59 54 60 template <class Function, class Input> … … 63 69 public: 64 70 function_pointer_input_iterator() {} 65 71 function_pointer_input_iterator(Function &f_, Input state_ = Input()) 66 : f(f_), state(state_), value((*f)()) 67 {} 72 : first(true), f(f_), state(state_), value() {} 68 73 69 74 void increment() { 70 75 value = (*f)(); … … 73 78 74 79 typename function_types::result_type<Function>::type const & 75 80 dereference() const { 81 if (first) { 82 value = (*f)(); 83 first = false; 84 } 76 85 return value; 77 86 } 78 87 … … 81 90 } 82 91 83 92 private: 93 mutable bool first; 84 94 Function f; 85 95 Input state; 86 typename function_types::result_type<Function>::type value;96 mutable typename function_types::result_type<Function>::type value; 87 97 }; 88 98 89 99 template <class Function, class Input> -
libs/iterator/doc/function_input_iterator.rst
1 1 :Author: 2 `Dean Michael Berris <mailto:m ikhailberis@gmail.com>`_2 `Dean Michael Berris <mailto:me@deanberris.com>`_ 3 3 4 4 :License: 5 5 Distributed under the Boost Software License, Version 1.0 6 6 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 7 8 :Copyright: 9 Copyright 2012 Google, Inc. 10 8 11 Function Input Iterator 9 12 ======================= 10 13 … … 112 115 copy( 113 116 make_function_input_iterator(f,infinite()), 114 117 make_function_input_iterator(f,infinite()), 115 ostream_iterator<int>(cou nt, " ")118 ostream_iterator<int>(cout, " ") 116 119 ); 117 120 118 121 Above, instead of creating a huge vector we rely on the STL copy algorithm