Boost logo

Boost Users :

From: jhr.walter_at_[hidden]
Date: 2003-03-05 02:25:30


Hi,

> *) First question:
>
> I am trying to get a reference to data of a container in the
> following way:
>
> matrix<double> m(3,3);
> vector<double>& v(m.column(2));
>
> But this seems not to be possible.
>
> Is there a way to achieve this behaviour?

Either use

matrix_column<matrix<double> > v (m.column (2)); // proxy[1]

or

vector<double> v (m.column (2)); // copy

> What I basically want to achive is having functor object that holds a
> reference to a row/column of my container matrix.

Looks like you'll need [1].

> >From my questions about argument types I know that m.column(2) is a
> kind of an expression. How can I get the underlying reference to data if
> there even
> is one?

You could start with m.column(2).data() and traverse the expression tree
then. In my experience this only is needed for special applications like
bindings to external libraries. I'd generally advise against using it.

> *) Second question:
>
> matrix<double> m(10,3);
>
> ... fill the matrix ...
>
> matrix<double>::iterator it; // wrong this does not work!!

matrix_column<matrix<double> >::iterator it;

> for (it = m.column(2).begin(); it != m.colum(2).end(); ++it) {
> cout << *it << " " << foo(*it) << endl;
> }
>
> How would I declare my iterator? I understand when I use
> std::library-algorithms the automatic template parameter defer will
> give me the correct type from begin(). But in my case how should I declare
the
> iterator?

HTH,

Joerg


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