Boost logo

Boost Users :

From: rodrigo_braz (rodrigo_braz_at_[hidden])
Date: 2002-03-14 22:01:50


Hi,
I don't see a reason for filter_iterator not to work with map
iterators.
However, the program below doesn't work.
I get a compiler error "Cannot generate template specialization
from 'make_filter_iterator<Predicate,Iterator>
(Iterator,Iterator,const Predicate &)' in function main()"

Any ideas?

Thanks,
Rodrigo

#include <map>
#include <ostream>
#include "boost/iterator_adaptors.hpp"
#include <algorithm>

using namespace std;
using namespace boost;

struct pair_is_active {
  bool operator()(const pair<const size_t,float>& p) { return 0 <
p.second; }
};

ostream& operator<<(ostream& o, pair<const size_t, float> p)
{
  return o << "(" << p.first << ", " << p.second << ")";
}

int main()
{
  map<size_t,float> m;
  m[0] = 10;
  m[1] = 15;
  m[2] = 0;
  m[3] = 13;

  copy(boost::make_filter_iterator<pair_is_active>(m.begin, m.end()),
       boost::make_filter_iterator<pair_is_active>(m.end(), m.end()),
       ostream_iterator<pair<const size_t,float> >(cout,","));

  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