Viktor Sehr
Viktor Sehr

Reputation: 13099

Whats the point of a move-constructor taking a constans rvalue?

According to http://en.cppreference.com/w/cpp/language/move_constructor; "A class can have multiple move constructors, e.g. both T::T(const T&&) and T::T(T&&)"

When would one want to pass a constant rvalue to the move-constructor?

Upvotes: 1

Views: 63

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477160

The short answer is "never".

However, you can indeed write a function like this:

Foo const f();

Now something like Foo x = f(); would use the Foo const && constructor if it is available. But it will also bind to the Foo const & constructor with pleasure, and since both references are constant, there's really no need for the rvalue version.

In particular, there's mothing "move" about that constructor, since, as we established, the reference is constant.

Upvotes: 1

Related Questions