Boost logo

Boost Users :

From: Chris Saunders (ctsa_at_[hidden])
Date: 2003-10-21 05:33:34

I've tried to compile one of the examples from the filter_iterator

  int numbers[] = { 0, -1, 4, -3, 5, 8, -2 };
  const int N = sizeof(numbers)/sizeof(int);

  std::copy(boost::make_filter_iterator(numbers, numbers + N,
            boost::make_filter_iterator(numbers + N, numbers + N,
            std::ostream_iterator<int>(std::cout, " "));
  std::cout << std::endl;


using a version of g++ 3.3.2 that has concept-checks enabled. In this case
the compiler rejects both of the iterators returned by
make_filter_iterator in the above code because they do not fulfill the
InputIterator concept required by std::copy. This is because InputIterator
requires the DefaultConstructable concept, and the predicate:
std::bind2nd(std::greater<int>(),-2) , isn't default constructable.

My question is this: is this type of iterator (non-default-constructable)
safe to use in general even if it fails a conceptual requirement? Of
course the above code runs as expected with a normal g++ build and I could
always wrap the predicate in another object if I really wanted to use
concept-checks... but I'm interested in whether the above code is
considered normal and safe as it stands.

Thanks for any insight.

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