I had start learning about the move semantics and come to know about rvalue references.
So, wanted to ask why do we need rvalue references if things can still work with references or simple call by value.
#include <iostream>
void func(int x){
std::cout<<x<<std::endl;
x += 1;
}
void func_ref(int &x){
std::cout<<x<<std::endl;
x += 1;
}
void func_rref(int &&x){
x += 1;
std::cout<<x<<std::endl;
}
int main()
{
int x = 1;
func(x);//1
x += 1;
func(x);//2
func_ref(x);//2
std::cout<<x<<std::endl;//3
func_rref(2);
return 0;
}
What's the use of this func_rref function how this is different from normal func where parameter passed as value or if parameter passed as reference ?