|
Ublas : |
Subject: Re: [ublas] vector< vector< T > > to matrix < T > assignment
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2010-09-13 04:05:00
On Sun, Sep 12, 2010 at 12:38 PM, Matwey V. Kornilov
<matwey.kornilov_at_[hidden]> wrote:
>
> In my opinion this is not exactly how it is.
>
> Consider function fun() returning vector< vector< T > >.
>
> matrix< T > m;
>
> // ...
>
> m = vector_of_vector_to_matrix( fun() );
> /* at least two memory copying. the first one is from temporary object of
> type vector<vector<T>> to matrix<T> in vector_of_vector_to_matrix(). the
> second is assignment this temporary matrix<T> into m object. */
>
> matrix< T > m2 = vector_of_vector_to_matrix( fun() );
> /* single copying. RVO or NRVO works here */
>
> When adapters are used there is single copying in both cases.
>
You're right. For such cases adaptor to (const) vector< vector<> > let
you save 1 copy.
-- Marco