Boost logo

Boost Users :

Subject: [Boost-users] Iterator behaving like an indirect_iterator and a filter_iterator
From: Teto (mattator_at_[hidden])
Date: 2009-09-01 06:43:04


Hi everyone,

I wanted to know if it was possible to have an iterator behaving like
both an indirect_iterator and a filter_iterator. I've tried to without
success.

Here is a minimal code that compiles but crashes.
=====================================
class CTest {

public:
CTest(int Value,int Id) : value(Value),id(Id) {};
int id;
int value;

};

std::vector<CTest*> vec;
vec.push_back(new CTest(4,7));
vec.push_back(new CTest(4,1));

//I want an iterator that I could use like iter->id / iter->value and
not (*iter)->id / (*iter)->value

struct SPredicate {
    bool operator()( C& x) {
        return (-1 < x.id);
    }
};

typedef boost::filter_iterator<SPredicate, CTest*> FilterIterator;

FilteredIterator end(*vec.end());

for(FilteredIterator iter(*vec.begin());start != end; iter++){
        std::cout << "id" << iter->id << "\tValue" << iter->m << std::endl;
}
=====================================

I'm new to boost and is very impressed by its possibilites. Hope I can
understand the code better later.

thanx
matt


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net