Boost logo

Boost :

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2002-10-06 09:49:11


For my ublas-to-blas bindings, I need to get hold of the internal-array. But
to get the pointer to the first element, I still have some 'unexpected'
failure : e.g.

#include <boost/numeric/ublas/vector.hpp>

int main()
{
  boost::numeric::ublas::vector< double > v(3);
  const boost::numeric::ublas::vector< double >& cv( v ) ;

  const double* a = &cv[0] ; // 1: does not compile
  const double* b = &*cv.begin() ; // 2: does not compile
  const double* c = &*cv.data().begin() ; // 3: compiles

  return 0 ;
}

>From the iterator_adaptor discussion, I learned that indeed 1 does not have
to compile (if a ublas::vector is like a std::vector where operator[] is only
required to return a type tha is convertible to T).

Case 2 however, I had expected that it would compile (AFAICT this is due to
the fact that the iterator returns a const_reference which is _incorrectly_ a
reference (uncommenting the following in the source makes it work)

</begin ublas source snippet>
// typedef const T &const_reference;
     typedef typename type_traits<T>::const_reference const_reference;
</end ublas source snippet>

As for case 3, I knew that matrices had a member data() for reasons we've
long time ago discussed, but was not aware that the vectors supported it too.
Anyway I'm glas I found it.

toon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk