Hans Åberg wrote:
> If I write:
>
> A& h(A& a) {
> return a;
> }
>
> A&& h(A&& a) {
> return std::move(a);
> }
h seems like a NOP.
> int main() {
> A a, b;
>
> b = std::move(h(a));
> b = std::move(h(std::move(a)));
You don't need "std::move" twice here.
> return EXIT_SUCCESS;
> }
>
> Then if A only has copy assignment, that will be used, but if has
> that and move assignment or only move assignment, then move
> assignment will be used. No copying occurs with copy elision.
You don't need h at all.
Simply "b = std::move (a);" will do the same. All it does is convert
a to an rvalue reference. If A has a move assignment operator, this
will be chosen, if it doesn't but a copy assignment operator, that
one will be chosen. That's all standard C++ behaviour.
> Isn't that what you want?
What I want (or actually have, since I imeplented it :) is a way to
make Bison apply std::move automatically.
Regards,
Frank