Boost logo

Boost Users :

Subject: Re: [Boost-users] [uBLAS] Predefined subrange or project
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-03-09 18:48:17


On 09/03/2011 17:11, Ryan wrote:
> On Wed, Mar 9, 2011 at 4:09 AM, Mathias Gaunard
> <mathias.gaunard_at_[hidden] <mailto:mathias.gaunard_at_[hidden]>> wrote:
>
> On 09/03/2011 09:59, sguazt wrote:
>
> namespace ublas = ::boost::numeric::ublas;
>
> template<typename MatrixT>
> inline
> ublas::matrix_range<MatrixT> topleft(MatrixT& M)
> {
> return ublas::subrange(M, 0, 3, 0, 3);
> }
>
> You might want to provide a const overload as well.
>
> Why would I want a const overload? I want to be able to change the
> values in the matrix passed to the function.

To allow rvalues and propagate constness, so as to make it behave more
like a typedef or macro.

In the snippet you gave, of course, it needs to be non-const. But it's
good practice to provide both when you write such adaptors.


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