ublas iterator problem

#include <boost/numeric/ublas/vector.hpp> namespace ublas = boost::numeric::ublas; void F () { ublas::vector<int> u (10); int y = *u.begin(); int x = u.begin()[0]; } This code fails to compile with g++34 + current boost.cvs. Test.cc:8: error: no match for 'operator[]' in 'boost::numeric::ublas::vector<T, A>::begin() [with T = int, A = boost::numeric::ublas::unbounded_array<int, std::allocator<int> >]()[0]' u.begin() should return an iterator, and the iterator should define operator[]. Why doesn't this work?

"Neal D. Becker" <ndbecker2@verizon.net> writes:
#include <boost/numeric/ublas/vector.hpp>
namespace ublas = boost::numeric::ublas;
void F () { ublas::vector<int> u (10); int y = *u.begin(); int x = u.begin()[0]; }
This code fails to compile with g++34 + current boost.cvs.
Test.cc:8: error: no match for 'operator[]' in 'boost::numeric::ublas::vector<T, A>::begin() [with T = int, A = boost::numeric::ublas::unbounded_array<int, std::allocator<int> >]()[0]'
u.begin() should return an iterator, and the iterator should define operator[]. Why doesn't this work?
If these are (supposedly) random access iterators, it's because the ublas people aren't using iterator_facade or iterator_adaptor to define them. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

David Abrahams wrote:
"Neal D. Becker" <ndbecker2@verizon.net> writes:
#include <boost/numeric/ublas/vector.hpp>
namespace ublas = boost::numeric::ublas;
void F () { ublas::vector<int> u (10); int y = *u.begin(); int x = u.begin()[0]; }
This code fails to compile with g++34 + current boost.cvs.
Test.cc:8: error: no match for 'operator[]' in 'boost::numeric::ublas::vector<T, A>::begin() [with T = int, A = boost::numeric::ublas::unbounded_array<int, std::allocator<int> >]()[0]'
u.begin() should return an iterator, and the iterator should define operator[]. Why doesn't this work?
If these are (supposedly) random access iterators, it's because the ublas people aren't using iterator_facade or iterator_adaptor to define them.
Actually, I'm having trouble tracing this. AFAICT, in vector.hpp // Array based vector class template<class T, class A> class vector: ... typedef typename A::const_iterator const_iterator_type; typedef typename A::iterator iterator_type; So for unbounded_array (the default) in storage.hpp: template<class T, class ALLOC> class unbounded_array { typedef const T *const_pointer; typedef T *pointer; ... // Iterators simply are pointers. typedef const_pointer const_iterator; Therefore, const_iterator (or iterator) for vector should just be a pointer and so [] gets applied to a plain pointer, which should work.
participants (3)
-
David Abrahams
-
Neal Becker
-
Neal D. Becker