|
Boost Users : |
Subject: Re: [Boost-users] Iterator behaving like an indirect_iterator and a filter_iterator
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-01 10:55:05
AMDG
Teto wrote:
> 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;
>
Try boost::filter_iterator<SPredicate,
boost::indirect_iterator<std::vector<CTest*>::const_iterator> >.
> 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.
>
In Christ,
Steven Watanabe
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