|
Boost Users : |
From: Stephen Gross (sgross_at_[hidden])
Date: 2005-09-13 09:49:57
Ok, I'm trying to learn the basics of filter_iterators. I've got a vector of
ints. I want to iterate across the vector and print out every positive value
in the vector. Currently, my code doesn't work because g++ doesn't like me
assigning a vector::iterator to a filtered_iterator. Obviously, I've missed
some crucial point on how the filtered_iterator is supposed to work. The
example code in the boost library doesn't really address this specific use.
Can someone show me how to make the code below work as intended?
Thanks in advance,
--Steve
==== CODE FOLLOWS ====
struct is_positive { bool operator() (int i) { return i >= 0; } };
int main()
{
std::vector<int> i;
i.push_back(-5);
i.push_back( 5);
i.push_back(-4);
i.push_back( 4);
i.push_back(-3);
i.push_back( 3);
i.push_back(-2);
i.push_back( 1);
typedef boost::filter_iterator<is_positive, std::vector<int>::iterator>
filter_itr;
for(filter_itr f = i.begin(); f != i.end(); ++f)
{
std::cout << *f << std::endl;
}
return 0;
}
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