|
Boost : |
Subject: Re: [boost] Preliminary submission: generic linear algebra algorithms library Boost LA
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-10-23 14:48:18
On Fri, Oct 23, 2009 at 11:27 AM, joel <joel.falcou_at_[hidden]> wrote:
> Emil Dotchevski wrote:
>>
>> Oh from this point of view yes, the library does allow you to get a
>> vector out of a given column or row of a matrix, you just go m|col<2>
>> and you get a vector type (without actually creating a temporary.)
>>
>
> What's the trick behind that ?
The op| overload takes m by reference, and returns the same reference
reinterpret_casted to reference to an instance of this template:
template <int Col,class OriginalMatrix>
class col_; //non-copyable
Then there is this partial specialization of the vector_traits template:
template <int Col,class OriginalMatrix>
struct vector_traits< col_<Col,OriginalMatrix> > { ... };
The element access functions in that specialization reinterpret_cast
the col_<> reference they get back to OriginalMatrix reference and
then forward the call to the access functions found in
matrix_traits<OriginalMatrix>.
There is a bunch of such op| overloads in (Boost) LA, and I wouldn't
be shy about adding more:
http://www.revergestudios.com/boost-la/view_proxy.html.
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk