19

Possible Duplicate:
What does T&& mean in C++0x?

I had never seen a double ampersand before I read this answer.

The code snippet in question is this:

template <typename T>
T& as_lvalue(T&& x)
{
    return x;
}

What does && achieve? What sorts of parameters can be passed to as_lvalue()

Community
  • 1
  • 1
paperjam
  • 8,321
  • 12
  • 53
  • 79
  • 3
    Some context would be useful in the title - I came here expecting a discussion of logical operators. – Mac Dec 07 '11 at 23:23

2 Answers2

12

It is called an rvalue reference, and it is new in C++11. It binds to temporaries without making a copy.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 8
    that doesn't really answer the question -- I have lots of experience in C++ prior to this new standard and my eyes just glaze over when I read the wikipedia page. – Jason S Dec 07 '11 at 23:24
  • 3
    The [MSDN article on the rvalue operator](http://msdn.microsoft.com/en-us/library/dd293668.aspx) is more extensive than that Wikipedia link. – Barend Dec 07 '11 at 23:27
  • 1
    @JasonS: It binds to temporaries without making a copy – Mooing Duck Dec 07 '11 at 23:29
0

Most common usage is short-circuit boolean and operator.

C++11 uses it for rvalue references. Your example uses that.

Pubby
  • 51,882
  • 13
  • 139
  • 180