Ticket #5825: boost-5825.patch

File boost-5825.patch, 3.4 KB (added by Dean Michael Berris, 10 years ago)

Fix to implementation and docs.

  • boost/iterator/function_input_iterator.hpp

     
    11// Copyright 2009 (C) Dean Michael Berris <me@deanberris.com>
     2// Copyright 2012 (C) Google, Inc.
    23// Distributed under the Boost Software License, Version 1.0. (See
    34// accompanying file LICENSE_1_0.txt or copy at
    45// http://www.boost.org/LICENSE_1_0.txt)
     
    2930        public:
    3031            function_input_iterator() {}
    3132            function_input_iterator(Function & f_, Input state_ = Input())
    32                 : f(&f_), state(state_), value((*f)()) {}
     33                : first(true), f(&f_), state(state_), value() {}
    3334
    3435            void increment() {
    3536                value = (*f)();
     
    3839
    3940            typename Function::result_type const &
    4041                dereference() const {
     42                    if (first) {
     43                      value = (*f)();
     44                      first = false;
     45                    }
    4146                    return value;
    4247            }
    4348
     
    4651            }
    4752
    4853        private:
     54            mutable bool first;
    4955            Function * f;
    5056            Input state;
    51             typename Function::result_type value;
     57            mutable typename Function::result_type value;
    5258        };
    5359
    5460        template <class Function, class Input>
     
    6369        public:
    6470            function_pointer_input_iterator() {}
    6571            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() {}
    6873
    6974            void increment() {
    7075                value = (*f)();
     
    7378
    7479            typename function_types::result_type<Function>::type const &
    7580                dereference() const {
     81                    if (first) {
     82                      value = (*f)();
     83                      first = false;
     84                    }
    7685                    return value;
    7786            }
    7887
     
    8190            }
    8291
    8392        private:
     93            mutable bool first;
    8494            Function f;
    8595            Input state;
    86             typename function_types::result_type<Function>::type value;
     96            mutable typename function_types::result_type<Function>::type value;
    8797        };
    8898
    8999        template <class Function, class Input>
  • libs/iterator/doc/function_input_iterator.rst

     
    11:Author:
    2     `Dean Michael Berris <mailto:mikhailberis@gmail.com>`_
     2    `Dean Michael Berris <mailto:me@deanberris.com>`_
    33
    44:License:
    55    Distributed under the Boost Software License, Version 1.0
    66    (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    77
     8:Copyright:
     9    Copyright 2012 Google, Inc.
     10
    811Function Input Iterator
    912=======================
    1013
     
    112115    copy(
    113116            make_function_input_iterator(f,infinite()),
    114117            make_function_input_iterator(f,infinite()),
    115             ostream_iterator<int>(count, " ")
     118            ostream_iterator<int>(cout, " ")
    116119        );
    117120   
    118121Above, instead of creating a huge vector we rely on the STL copy algorithm