Boost logo

Boost :

Subject: [boost] Function Input Iterator Implementation (Interest Check, Submission)
From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2009-03-25 19:49:30

Hi Everyone,

Let's say I have a function object that I wrap in a generator iterator
and I want it to signal that it's done generating values or that
there's nothing more to generate. In the current version of the
Generator Iterator, there's no way to create an iterator that has a
bound. This is great if you want an infinite input iterator, but there
are cases where you might want one that is bounded (or at least,
create a pair of iterators representing a range gotten from an
infinite source).

I've attached the implementation of a proposed
'function_input_iterator' which allows the creation of bounded input
ranges from a nullary function object which models the Generator
concept. This doesn't aim to replace the generator_iterator
implementation, but rather is an implementation that allows for the
following use case:


#include <boost/function_input_iterator.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

struct generator {
  typedef int result_type;
  generator() { srand(time(0)); }
  result_type operator() () const { return rand(); }

using namespace std;
using namespace boost;

int main(int argc, char * argv[]) {
  generator f;
    make_function_input_iterator(f, infinite()),
    make_function_input_iterator(f, infinite()),
    ostream_iterator<int>(cout, " ")
  return 0;


In the attached implementation, I've implemented a simple 'infinite'
class that supports the post- and pre-increment operator and
comparison between two infinite instances always result to false. This
allows the use of infinite() as a dummy state variable internal to the
function_input_iterator to make sure that the created range resulting
from the iterator is infinite.

Another use case enabled is given below:


  make_function_input_iterator(f, 0),
  make_function_input_iterator(f, 10),
  ostream_iterator<int>(cout, " ")


This creates a range of 10 random numbers. If we were going to
populate an STL container using the range constructors, we can do:

vector<int> random_ints(
    make_function_input_iterator(f, 0),
    make_function_input_iterator(f, 10)

I'm currently in the process of writing documentation in RST format.
I'm submitting this implementation to Boost in case there's interest
for inclusion.

Question: Does a library like this qualify for a fast-track review?
What is the criteria for inclusion to an existing library like

Thanks in advance and I hope this helps!

Dean Michael Berris | Software Engineer, Friendster, Inc. | | | |

Boost list run by bdawes at, gregod at, cpdaniel at, john at