As I know, perfect forwarding is design for reducing the need of
many overloaded functions when you pass the reference to the function
and pass those reference to another functions

Besides, to fullfill the objective of perfect forwarding
&& should be able to swallow the lvalue and rvalue
That means I could write something like this

void accept(int const& a, int const& b) {}
void accept(int& a, int& b) {}
void accept(int const& a, int& b) {}
void accept(int& a, int const& b) {}
void testPF(int&& a, int&& b) {}

int main()
{ 
 testPF(2, 3);//ok
 int a = 10, b = 20;
 testPF(a, b);//error
}

error message
error: cannot bind 'int' lvalue to 'int&&'

my compilers : tdm gcc4.5.2
my os : windows xp sp3(32)

Thanks a lot

Recommended Answers

All 3 Replies

Maybe this?

testPF(std::move(a), std::move(b))

So the instructions of MSDN is wrong(although it is not a standard at all)?
And according to my understanding, I can't gain benefit from POD with rvalue reference

#include<vector>

struct Point
{
  int x;
  int y;  
};

int main()
{
  std::vector<Point> temp;
  Point A;
  A.x = 100; A.y = 200;
  temp.push_back(A);
  temp.push_back(std::move(A));//can't take any advantage
}

Am I right?Thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.