Boost logo

Boost :

From: Neal D. Becker (ndbecker2_at_[hidden])
Date: 2004-05-14 07:03:53


Vladimir Prus wrote:

> Neal D. Becker wrote:
>> Thanks for the advice. I think I have it now.
>>
>> Problem:
>>
>> A function F accepts a pair of stl-style iterators as input. A nullary
>> functor G can generate an output. Arrange for F to call G n times
>> without storing to an intermediate sequence.
>>
>> Example: G is a random number generator.
>>
>> I wonder if there is a more elegant approach?
>
>

> As for improving this, I also have two ideas:
>
> 1. Some time ago I've created an utility class for creating input
> iterators, called "eof_iterator". Reimplementing function_input_iterator
> with it yeilds somewhat smaller code, see:
>
> http://zigzag.cs.msu.su:7813/iterators/function_input_iterator2.hpp
>
> the eof iterator itself is at:
>
> http://zigzag.cs.msu.su:7813/iterators/eof_iterator.hpp
>

I love it! Just one small improvement:

eof_iterator add parameter:

  template<class Derived, class ValueType, class
traversal_type=forward_traversal_tag>
    class eof_iterator : public iterator_facade<Derived, const ValueType,
                                                traversal_type>

And change function_input_iterator:

template<class FUNC>
class function_input_iterator2 : public boost::eof_iterator<
  function_input_iterator2<FUNC>,
  typename boost::remove_reference<FUNC>::type::result_type,
  boost::single_pass_traversal_tag
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk