Forwarding references
One of the most important features that were added to the language in C++11 is move semantics, which helps improve performance by avoiding making unnecessary copies. Move semantics are supported by another C++11 feature called rvalue references. Before discussing these, it is worth mentioning that, in C++, we have two kinds of values:
- lvalues are values that refer to a memory location and, therefore, we can take their address with the
&
operator. lvalues can appear both on the left and right sides of an assignment expression. - rvalues are values that are not lvalues. They are defined by exclusion. rvalues do not refer to a memory location and you can’t take their address with the
&
operator. rvalues are literals and temporary objects and can only appear on the right side of an assignment expression.Note
In C++11, there are a few other value categories, glvalue, prvalue, and xvalue. Discussing them here would not benefit the current topic...