Move operators

Joaquim Duran Comas <[email protected]>
Newsgroups gmane.comp.lib.boost.ublas
Message-ID <CAMnFju7Dov90h6-mxq3d0uijfKrwCk_05Ma77Hi3rP24xCx2kQ@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.