Boost logo

Boost Users :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2003-10-21 09:15:40

Hi Chris,

It looks like there is a bug in the iterator concept checks. When I first
created the concept checks, I was using the SGI STL web pages as a
reference... and at that time I didn't know there were subtle differences
between the SGI concepts and the C++ standard. Anyways, the C++ standard
does not require an Input Iterator to be default constructible (the SGI
docs do), so the code below should be legal.


On Tue, 21 Oct 2003, Chris Saunders wrote:
ctsa> I've tried to compile one of the examples from the filter_iterator
ctsa> documentation:
ctsa> main()
ctsa> {
ctsa> int numbers[] = { 0, -1, 4, -3, 5, 8, -2 };
ctsa> const int N = sizeof(numbers)/sizeof(int);
ctsa> std::copy(boost::make_filter_iterator(numbers, numbers + N,
ctsa> std::bind2nd(std::greater<int>(),
ctsa> -2)),
ctsa> boost::make_filter_iterator(numbers + N, numbers + N,
ctsa> std::bind2nd(std::greater<int>(),
ctsa> -2)),
ctsa> std::ostream_iterator<int>(std::cout, " "));
ctsa> std::cout << std::endl;
ctsa> }
ctsa> using a version of g++ 3.3.2 that has concept-checks enabled. In this case
ctsa> the compiler rejects both of the iterators returned by
ctsa> make_filter_iterator in the above code because they do not fulfill the
ctsa> InputIterator concept required by std::copy. This is because InputIterator
ctsa> requires the DefaultConstructable concept, and the predicate:
ctsa> std::bind2nd(std::greater<int>(),-2) , isn't default constructable.
ctsa> My question is this: is this type of iterator (non-default-constructable)
ctsa> safe to use in general even if it fails a conceptual requirement? Of
ctsa> course the above code runs as expected with a normal g++ build and I could
ctsa> always wrap the predicate in another object if I really wanted to use
ctsa> concept-checks... but I'm interested in whether the above code is
ctsa> considered normal and safe as it stands.

 Jeremy Siek
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster ( office phone: (812) 855-3608

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