Function Input Iterator (Boost Submission)
A couple of weeks ago I've submitted an implementation of a "Function Input Iterator" that builds upon the implementation of the generator iterator adaptor. The function input iterator implementation uses a separate state object that tracks the state of the iterator. The state encapsulated by the iterator is used to compare whether two iterators are equal.
The library has been submitted as an additional library to the Boost.Iterators library and is part of the Trac ticket #2893. From the ticket submission, the following details are then quoted.
Simply put a the function input iterator implementation wraps a nullary function object and allows for bounded iterators using an embedded state variable. The use case is for something like the following:
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; copy( make_function_input_iterator(f, infinite()), make_function_input_iterator(f, infinite()), ostream_iterator(cout, " ") ); return 0; } And if you don't want an infinite range, you can simply bound it:
copy( make_function_input_iterator(f, 0), make_function_input_iterator(f, 10), ostream_iterator(cout, " ") );



1 comments:
Just discovered yr blog 5/21 ... like it a lot. Subs via RSS and Goo Reader.
Bill Drissel
Post a Comment