[multi_array] Bug in rbegin(), rend()?

I'm having some trouble iterating over a 2-dimensional multi_array in reverse order. I'm using boost 1.38 with gcc-4.2.4 and the following code won't compile with the error given below: #include <boost/multi_array.hpp> template< typename It > void iterate_over( It begin, It end ) { while( end != begin ) { begin->end() - begin->begin(); ++begin; } } void test() { boost::multi_array< double, 2 > m; iterate_over( m.begin(), m.end() ); // works fine iterate_over( m.rbegin(), m.rend() ); // causes error } This looks to me like a bug in the implementation of the reverse iterator for multi_array. Am I wrong? John. /home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp: In static member function ‘static typename boost::mpl::if_<boost::is_reference<Reference>, Pointer, boost::detail::operator_arrow_proxy<ValueType> >::type boost::detail::operator_arrow_result<ValueType, Reference, Pointer>::make(Reference) [with ValueType = boost::multi_array<double, 1ul, std::allocator<double> >, Reference = boost::detail::multi_array::sub_array<double, 1ul>, Pointer = boost::multi_array<double, 1ul, std::allocator<double> >*]’: /home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp:648: instantiated from ‘typename boost::detail::operator_arrow_result<typename boost::detail::iterator_facade_types<Value, CategoryOrTraversal, Reference, Difference>::value_type, Reference, typename boost::detail::iterator_facade_types<Value, CategoryOrTraversal, Reference, Difference>::pointer>::type boost::iterator_facade<I, V, TC, R, D>::operator->() const [with Derived = boost::reverse_iterator<boost::detail::multi_array::array_iterator<double, double*, mpl_::size_t<2ul>, boost::detail::multi_array::sub_array<double, 1ul> > >, Value = boost::multi_array<double, 1ul, std::allocator<double> >, CategoryOrTraversal = boost::detail::iterator_category_with_traversal<std::input_iterator_tag, boost::random_access_traversal_tag>, Reference = boost::detail::multi_array::sub_array<double, 1ul>, Difference = long int]’ src/sandbox/seqan_sandbox.cpp:12: instantiated from ‘void iterate_over(It, It) [with It = boost::reverse_iterator<boost::detail::multi_array::array_iterator<double, double*, mpl_::size_t<2ul>, boost::detail::multi_array::sub_array<double, 1ul> > >]’ src/sandbox/seqan_sandbox.cpp:22: instantiated from here /home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp:326: error: no matching function for call to ‘implicit_cast(boost::detail::multi_array::sub_array<double, 1ul>*)’

Agreed John. Getting the same error here. I believe it is a bug in the class <iterator_facade> Lets see how the moderator reacts.... Cheers Tushar On 5/19/09, John Reid <j.reid@mail.cryst.bbk.ac.uk> wrote:
I'm having some trouble iterating over a 2-dimensional multi_array in reverse order. I'm using boost 1.38 with gcc-4.2.4 and the following code won't compile with the error given below:
#include <boost/multi_array.hpp>
template< typename It > void iterate_over( It begin, It end ) { while( end != begin ) { begin->end() - begin->begin(); ++begin; } }
void test() { boost::multi_array< double, 2 > m; iterate_over( m.begin(), m.end() ); // works fine iterate_over( m.rbegin(), m.rend() ); // causes error }
This looks to me like a bug in the implementation of the reverse iterator for multi_array. Am I wrong?
John.
/home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp: In static member function ‘static typename boost::mpl::if_<boost::is_reference<Reference>, Pointer, boost::detail::operator_arrow_proxy<ValueType> >::type boost::detail::operator_arrow_result<ValueType, Reference, Pointer>::make(Reference) [with ValueType = boost::multi_array<double, 1ul, std::allocator<double> >, Reference = boost::detail::multi_array::sub_array<double, 1ul>, Pointer = boost::multi_array<double, 1ul, std::allocator<double> >*]’: /home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp:648: instantiated from ‘typename boost::detail::operator_arrow_result<typename boost::detail::iterator_facade_types<Value, CategoryOrTraversal, Reference, Difference>::value_type, Reference, typename boost::detail::iterator_facade_types<Value, CategoryOrTraversal, Reference, Difference>::pointer>::type boost::iterator_facade<I, V, TC, R, D>::operator->() const [with Derived = boost::reverse_iterator<boost::detail::multi_array::array_iterator<double, double*, mpl_::size_t<2ul>, boost::detail::multi_array::sub_array<double, 1ul> > >, Value = boost::multi_array<double, 1ul, std::allocator<double> >, CategoryOrTraversal = boost::detail::iterator_category_with_traversal<std::input_iterator_tag, boost::random_access_traversal_tag>, Reference = boost::detail::multi_array::sub_array<double, 1ul>, Difference = long int]’ src/sandbox/seqan_sandbox.cpp:12: instantiated from ‘void iterate_over(It, It) [with It = boost::reverse_iterator<boost::detail::multi_array::array_iterator<double, double*, mpl_::size_t<2ul>, boost::detail::multi_array::sub_array<double, 1ul> > >]’ src/sandbox/seqan_sandbox.cpp:22: instantiated from here /home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp:326: error: no matching function for call to ‘implicit_cast(boost::detail::multi_array::sub_array<double, 1ul>*)’
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Tushar Chowdhury wrote:
Agreed John. Getting the same error here.
I believe it is a bug in the class <iterator_facade>
As far as I can tell multi_array seems to use the iterator facade to define its iterator and uses boost::reverse_iterator to define its reverse iterator. I'm not sure if the problem is in multi_array, iterator_facade or reverse_iterator. John.
On 5/19/09, John Reid <j.reid@mail.cryst.bbk.ac.uk> wrote:
I'm having some trouble iterating over a 2-dimensional multi_array in reverse order. I'm using boost 1.38 with gcc-4.2.4 and the following code won't compile with the error given below:
#include <boost/multi_array.hpp>
template< typename It > void iterate_over( It begin, It end ) { while( end != begin ) { begin->end() - begin->begin(); ++begin; } }
void test() { boost::multi_array< double, 2 > m; iterate_over( m.begin(), m.end() ); // works fine iterate_over( m.rbegin(), m.rend() ); // causes error }
This looks to me like a bug in the implementation of the reverse iterator for multi_array. Am I wrong?
John.
/home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp: In static member function ‘static typename boost::mpl::if_<boost::is_reference<Reference>, Pointer, boost::detail::operator_arrow_proxy<ValueType> >::type boost::detail::operator_arrow_result<ValueType, Reference, Pointer>::make(Reference) [with ValueType = boost::multi_array<double, 1ul, std::allocator<double> >, Reference = boost::detail::multi_array::sub_array<double, 1ul>, Pointer = boost::multi_array<double, 1ul, std::allocator<double> >*]’: /home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp:648: instantiated from ‘typename boost::detail::operator_arrow_result<typename boost::detail::iterator_facade_types<Value, CategoryOrTraversal, Reference, Difference>::value_type, Reference, typename boost::detail::iterator_facade_types<Value, CategoryOrTraversal, Reference, Difference>::pointer>::type boost::iterator_facade<I, V, TC, R, D>::operator->() const [with Derived = boost::reverse_iterator<boost::detail::multi_array::array_iterator<double, double*, mpl_::size_t<2ul>, boost::detail::multi_array::sub_array<double, 1ul> > >, Value = boost::multi_array<double, 1ul, std::allocator<double> >, CategoryOrTraversal = boost::detail::iterator_category_with_traversal<std::input_iterator_tag, boost::random_access_traversal_tag>, Reference = boost::detail::multi_array::sub_array<double, 1ul>, Difference = long int]’ src/sandbox/seqan_sandbox.cpp:12: instantiated from ‘void iterate_over(It, It) [with It = boost::reverse_iterator<boost::detail::multi_array::array_iterator<double, double*, mpl_::size_t<2ul>, boost::detail::multi_array::sub_array<double, 1ul> > >]’ src/sandbox/seqan_sandbox.cpp:22: instantiated from here /home/john/Dev/ThirdParty/boost/boost_1_38_0/boost/iterator/iterator_facade.hpp:326: error: no matching function for call to ‘implicit_cast(boost::detail::multi_array::sub_array<double, 1ul>*)’
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

John Reid wrote:
On 5/19/09, John Reid <j.reid@mail.cryst.bbk.ac.uk> wrote:
I'm having some trouble iterating over a 2-dimensional multi_array in reverse order. I'm using boost 1.38 with gcc-4.2.4 and the following code won't compile with the error given below:
#include <boost/multi_array.hpp>
template< typename It > void iterate_over( It begin, It end ) { while( end != begin ) { begin->end() - begin->begin(); ++begin; } }
void test() { boost::multi_array< double, 2 > m; iterate_over( m.begin(), m.end() ); // works fine iterate_over( m.rbegin(), m.rend() ); // causes error }
This looks to me like a bug in the implementation of the reverse iterator for multi_array. Am I wrong?
The problem only manifests itself when the operator-> is used on the reverse iterator. Replacing begin->end() - begin->begin() with (*begin).end() - (*begin).begin() works fine

Tushar Chowdhury wrote:
Agreed John. Getting the same error here.
I believe it is a bug in the class <iterator_facade>
Lets see how the moderator reacts....
FYI I filed a bug report: https://svn.boost.org/trac/boost/ticket/3077
participants (2)
-
John Reid
-
Tushar Chowdhury