Boost logo

Boost Users :

From: Witz (witz_at_[hidden])
Date: 2003-10-04 17:52:46


I would like to raise a couple of points about the iterator adaptors.

Firstly, is it really necessary to have the predicate as part of the
template specification for the filter_iterator? Surely it can be assumed
that it will always be convertible to boost::function<bool (const
value_type&)> ?

Secondly, by allowing the return type of the function used by the
transform_iterator to be a reference can we not use it to implement a more
generic form of indirect_iterator? The code below gives a flavour of the idea.

    struct dereference
       typedef int result_type;

       int* data_;

       dereference(int* data):data_(data){}
       int operator()(int i) const { return data_[i]; }

    int main()
       int data[] = { 1,2,3,4,5,6,7,8 };
       int keys[] = { 0,3,1,6,5,4,2,7 };

       typedef boost::transform_iterator_generator<dereference, int*>::type

       indirect_iterator i(keys, dereference(data)),

       while(i != i_end)
          std::cout << *i++ << ' ';

       return 0;

    The output is:

    1 4 2 7 6 5 3 8


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at