Following code:
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/join.hpp>
struct foo {
typedef int result_type;
result_type operator ()(int x) { return x; }
};
int main() {
using boost::adaptors::transformed;
int a[] = {1, 2, 3};
boost::join(a | transformed(foo()), a | transformed(foo()));
return 0;
}
will get a compile error:
error C2039: 'type' : is not a member of 'boost::range_d开发者_运维问答etail::demote_iterator_traversal_tag<IteratorTraversalTag1,IteratorTraversalTag2>'
1> with
1> [
1> IteratorTraversalTag1=boost::detail::iterator_category_with_traversal<std::input_iterator_tag,boost::random_access_traversal_tag>,
1> IteratorTraversalTag2=boost::detail::iterator_category_with_traversal<std::input_iterator_tag,boost::random_access_traversal_tag>
1> ]
...
in VS2008 with boost 1.45.
I dived into the source code of boost::range_detail::demote_iterator_traversal_tag
and found it doesn't give a consideration about boost::detail::iterator_category_with_traversal
which is produced by boost::detail::facade_iterator_category
used by iterator_facade
to deduce proper iterator category.
The transform_iterator
is based on iterator_facade
, so the iterator category of a | transformed(foo())
is deduced to be iterator_category_with_traversal<std::input_iterator_tag,boost::random_access_traversal_tag>
, but demote_iterator_traversal_tag
don't recognize it.
I don't understand why demote_iterator_traversal_tag
designed like this. Or maybe its just a bug?
Thanks.
In case any future Google users end up here like I did, yes it looks like this was a bug, because it is fixed in at least version 1.54 (probably sooner, I hit the bug using 1.44 and just downloaded the current version).
IteratorTraversalTag1
and IteratorTraversalTag2
derive both from std::input_iterator_tag
and boost::random_access_traversal_tag
. Thus the demote_iterator_traversal_tag
should have matched with BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, random_access_traversal_tag, random_access_traversal_tag )
. The ::type
should have been random_access_traversal_tag
. This looks really like a bug.
精彩评论