dimanche 17 mai 2015

What is the use of rvalue reference member variables

I was wondering if there is a point in having a rvalue reference variable (not as a function parameter)? I understand the use of rvalue reference when it is used as a function variable as then it is possible to avoid unnecessary allocations etc. But is there a use case rvalue reference variables that are not function parameters? Initially I thought that with such variables we could capture data that was passed in as rvalue for use later, but it seems that if we have a rvalue reference variable, then we can already take its address and therefore it can not be rvalue reference anymore.

I tried the following code and it ( unsurprisingly ) does not compile. So why would I ever want to have a rvalue reference variable?

void test(int&& a) {}

int&& a(22);
test(a);

Thanks!

Aucun commentaire:

Enregistrer un commentaire