dimanche 30 juin 2019

Why not define rvalue reference to be rvalue expression?

Let's consider the following code:

class X {
    std::vector<int> _v;
public:
    X(std::vector<int>&& v): _v(std::move(v)) {}
};

The compiler calls this constructor only for objects that can be moved. So why not just define an rvalue references to be rvalue expressions and don't write every time std::move for them?

The ctor member initializayion list would look like:

_v(v)

But this would still be a move, not a copy.

Aucun commentaire:

Enregistrer un commentaire