Boost logo

Boost :

Subject: [boost] [iterator] Interest check in specialized reproduction_iterator
From: Christoph Heindl (christoph.heindl_at_[hidden])
Date: 2009-11-17 11:55:29


Good afternoon,

Would there be interest in adding a specialized iterator, called
reproduction_iterator, that allows specifying a single element which
is iterated n-times.

Example:

const std::vector<int> values = boost::assign::list_of(1)(2)(3)(5);
const int c = 3;
std::vector<int> result;

std::transform(
  extboost::make_reproduction_iterator(c),
  extboost::make_reproduction_iterator(c, values.size()),
  values.begin(),
  std::back_inserter(result),
  std::multiplies<int>()
);

// result contains 3, 6, 9, 15

The rationale for implementing the iterator is to provide a mechanism
for the cheap iteration over a 'sequence' of equal objects. This is
used (in my case) for adaption of functions that otherwise take two
ranges and where I can bind one range to a single object.

In the example above one can achieve the same effect by using a binder
and std::transform that takes a single range. This is IMHO not always
possible.

'reproduction_iterator' is implemented as random access iterator using
boost::iterator_facade.

Best regards,
Christoph


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