Published January 1, 0001

C++ shines when we want low-level control over the memory. Copy-vs-move construction is one such instance.

Value categories

The std library often creates function objects. For e.g. XXX.

The goal of this post is to demystify T&&.

Before we get into reference collapsing, it’d help to establish template argument deduction. From the official CPP docs, we see Rule 4 when deducing P to A is: “If P is an rvalue reference to a cv-unqualified template parameter (so-called forwarding references), and the corresponding function call argument is an lvalue, the type lvalue reference to A is used in place of A for deduction”.

We can examine this via an AST dump.

XXX

So whenever we pass in x whose value category is an l-value, we are in fact passing in an l-value reference.