Subject: Re: [ublas] vector< vector< T > > to matrix < T > assignment
From: Matwey V. Kornilov (matwey.kornilov_at_[hidden])
Date: 2010-09-12 06:38:22
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.
Marco Guazzone wrote:
> Adaptors are good if you want that a type only behaves like another
> type, *without* copying data. So any change in the adaptor object
> (will change the adapted one).
> Instead if you want to simply copy a v< v<> > into a matrix, adaptor
> is useless (IMHO); a free function is better.
> -- Marco