Boost logo

Ublas :

Subject: Re: [ublas] Move operators
From: Joaquim Duran Comas (jdurancomas_at_[hidden])
Date: 2015-04-23 17:55:00


Ok, I see. I was thinking that it was intended to be compatible with C++11.

Joaquim Duran

2015-04-23 20:07 GMT+02:00 Nasos Iliopoulos <nasos_i_at_[hidden]>:

> Joaquim,
> the move semantics in uBlas were implemented before the C++11 standard was
> adopted. We will need update the implementation to reflect the C++11
> changes with respect to move constructors. I would say that gcc's vector
> implementation of the C++11 constructors design is a good reference
> implementation.
>
> Best,
> Nasos
>
>
>
> On 04/21/2015 07:13 PM, Joaquim Duran Comas wrote:
>
> Hello all,
>
> I've some questions regarding to move operators:
>
> 1 - As Houndie, in request #20 in boost/org/ublas, I would like to include
> the rreference operator (&&) before the matrix parameter:
>
> - fixed_matrix &operator = (fixed_matrix m) {
> + fixed_matrix &operator = (fixed_matrix && m) {
>
> This is how I've seen defined the move operator in may places. However,
> the comment tells that the parameter is passed by value to enable the move
> semantics. I've searched about move operator with parameter by value. I've
> found this article
> http://cpptruths.blogspot.com.es/2012/03/rvalue-references-in-constructor-when.html
> .
>
> The article tells that to activate the move semantics, the parameter
> should be passed by value (as you tell), but it is not applied the the move
> constructor or move iterator:
>
> class Book {
> public:
> Book(std::string title,
> std::vector<std::string> authors, // <-- Parameter by value
> size_t pub_day
> std::string pub_month,
> size_t pub_year)
> : _title (std::move(title)),
> _authors (std::move(authors)), // <-- The parameter is moved to
> member variable
> _pub_day (pub_day),
> _pub_month(std::move(pub_month)),
> _pub_year (pub_year)
> {}
>
> // ....
> // ....
> };
>
> 2 - AFAIK, with the implementation of move semantics has not deprecated
> the copy semantics. As it is defined in the source code, it looks like that
> move semantic could not be used with copy semantics. Both semantics should
> be used at the same time in a C++11 compiler:
>
> // Copy semantics
> matrix m1;
> matrix m2(m1);
> m2 = m1;
>
> // Move semantics
> matrix m1;
> matrix m2(std::move(m1));
> m3 = std::move(m2);
>
> Please, could you confirm that move operators are defined as expected?
>
> Thanks and Best Regards,
> Joaquim Duran
>
>
>
> _______________________________________________
> ublas mailing listublas_at_[hidden]http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: nasos_i_at_[hidden]
>
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: jdurancomas_at_[hidden]
>