Boost logo

Boost Users :

From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-06-13 05:50:48


Hoi Maarten :-)

Maarten Nieber wrote:
> Recently I found out that the ublas matrix uses T& when creating a
> reference to a matrix element.
> This causes a problem for me, as I'm developing an ublas matrix that
> has its data on disk rather than in memory:
>
> ublas::matrix< double, row_major, DiskStorage > m; // stores data on
> disk
>
> I would like ublas::matrix to use the reference type that is
> declared by its storage type.
>
> typedef A::reference reference;

So you would like to replace the following two lines in matrix.hpp
(within the definition of boost::matrix):

  typedef const T &const_reference;
  typedef T &reference;

By the following:

  typedef typename A::const_reference const_reference;
  typedef typename A::reference reference;

Right? (Mind the typename!) And in your case, A is your DiskStorage
class.

> My question is: is this a mistake in the design, or is there a
> reason why T& should always be the reference type of an ublas
> matrix?

When you locally make the changes to your copy of matrix.hpp, does it
all work for you? I don't have an answer to your question, I just hope
that it will get some more attention...

> As an illustration, here is some code using the reference type of
> the DiskStorage class:
>
> DiskStorage aDiskStorage( 100 ); // create a disk storage with 100
> elements
> DiskStorage::reference r = aDiskStorage[0];
> r = 123.456; // writes 123.456 to disk

Cool. :-)

Kind regards,

--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net