class foo
{
public:
int a;
foo(int i) {
a = i;
}
foo(foo &&f)
{
this->a = f.a;
f.a = 0;
std::cout << "move";
}
foo(const foo &f)
{
this->a = f.a;
std::cout << "ref";
}
};
template <typename A>
void E(A &&a)
{
cout << endl << is_lvalue_reference<A>::value << is_rvalue_reference<A>::value << is_reference<A>::value << endl;
a.a = 5;
}
template <typename A>
void f(A &&a)
{
cout << is_lvalue_reference<A>::value << is_rvalue_reference<A>::value << is_reference<A>::value << endl;
std::cout << a.a;
E(std::forward<A>(a));
std::cout << a.a;
}
int main()
{
f(foo(1));
}
After struggling with the rvalue and lvalue, I still get confused with the output of the code snippet below:
000
1
000
5
why the value of is_rvalue_reference<A>::value
in function f
got 0 instead of 1 ?