1 Jun 2010 01:25
Re: [gil] Is bit_aligned_pixel_iterator a standard conformant random access iterator?
Adam Merz <adammerz <at> hotmail.com>
2010-05-31 23:25:44 GMT
2010-05-31 23:25:44 GMT
Hi Christian, this is ildjarn from the MSDN forums.(Continue reading)Christian Henning <chhenning <at> gmail.com> writes: > Hi there, I'm having an interesting discussion over at the MSDN forums > regarding compiler errors with MSVC10 that show up when using standard > algorithms and bit_aligned images. Basically the question is why > MSVC10 doesn't understand that bit_aligned_pixel_iterator is a random > access iterator. To be clear, it's not that MSVC10 doesn't understand that bit_aligned_pixel_iterator is a random access iterator, it's that bit_aligned_pixel_iterator *isn't* a random access iterator. I.e., std::iterator_traits< bit_aligned_pixel_iterator >::iterator_category is std::input_iterator_tag on every compiler/platform. It's just that MSVC10 refuses to instantiate std::copy given a destination iterator categorized as an input iterator (which is a good thing). If GIL had a regression test with a static assertion that boost::is_same< std::iterator_traits< bit_aligned_pixel_iterator<...> >::iterator_category, std::random_access_iterator_tag >::value == true, this would have been caught long ago. (hint, hint) One perspective is that the bug here is that bit_aligned_pixel_iterator is trying to pass itself off as a random access iterator in the first place, despite the fact that it returns a proxy object rather than an actual reference, violating the standard's requirements for forward iterators. However, since it appears to work properly on all tested toolsets, that could be deemed an acceptable flaw, in which case the proper fix is to pass iterator_facade a category of std::random_access_iterator_tag rather than boost::random_access_traversal_tag. Easy enough.
![]()
Christian Henning <chhenning <at> gmail.com> writes:
> Hi there, I'm having an interesting discussion over at the MSDN forums
> regarding compiler errors with MSVC10 that show up when using standard
> algorithms and bit_aligned images. Basically the question is why
> MSVC10 doesn't understand that bit_aligned_pixel_iterator is a random
> access iterator.
To be clear, it's not that MSVC10 doesn't understand that
bit_aligned_pixel_iterator is a random access iterator, it's that
bit_aligned_pixel_iterator *isn't* a random access iterator. I.e.,
std::iterator_traits< bit_aligned_pixel_iterator >::iterator_category is
std::input_iterator_tag on every compiler/platform. It's just that MSVC10
refuses to instantiate std::copy given a destination iterator categorized as an
input iterator (which is a good thing). If GIL had a regression test with a
static assertion that boost::is_same< std::iterator_traits<
bit_aligned_pixel_iterator<...> >::iterator_category,
std::random_access_iterator_tag >::value == true, this would have been caught
long ago. (hint, hint)
One perspective is that the bug here is that bit_aligned_pixel_iterator is
trying to pass itself off as a random access iterator in the first place,
despite the fact that it returns a proxy object rather than an actual
reference, violating the standard's requirements for forward iterators.
However, since it appears to work properly on all tested toolsets, that could
be deemed an acceptable flaw, in which case the proper fix is to pass
iterator_facade a category of std::random_access_iterator_tag rather than
boost::random_access_traversal_tag. Easy enough.
> To be clear, it's not that MSVC10 doesn't understand that
> bit_aligned_pixel_iterator is a random access iterator, it's that
> bit_aligned_pixel_iterator *isn't* a random access iterator. I.e.,
> std::iterator_traits< bit_aligned_pixel_iterator >::iterator_category is
> std::input_iterator_tag on every compiler/platform. It's just that MSVC10
> refuses to instantiate std::copy given a destination iterator categorized as an
> input iterator (which is a good thing). If GIL had a regression test with a
> static assertion that boost::is_same< std::iterator_traits<
> bit_aligned_pixel_iterator<...> >::iterator_category,
> std::random_access_iterator_tag >::value == true, this would have been caught
> long ago. (hint, hint)
>
> One perspective is that the bug here is that bit_aligned_pixel_iterator is
> trying to pass itself off as a random access iterator in the first place,
> despite the fact that it returns a proxy object rather than an actual
> reference, violating the standard's requirements for forward iterators.
> However, since it appears to work properly on all tested toolsets, that could
> be deemed an acceptable flaw, in which case the proper fix is to pass
> iterator_facade a category of std::random_access_iterator_tag rather than
> boost::random_access_traversal_tag. Easy enough.
RSS Feed