C++11 Universal Reference

 

Q1. 什么是universal reference?

If a variable or parameter is declared to have type T&& for some deduced type T, that variable or parameter is a universal reference.

 

Q2. 什么是deduced typeT?

A2. Template parameter、auto declaration, ect.

 

Q3. universal reference 是什么类型?

  • If the expression initializing a universal reference is an lvalue, the universal reference becomes an lvalue reference.
  • If the expression initializing the universal reference is an rvalue, the universal reference becomes an rvalue reference.

Q4. 什么是lvalue(左值),什么是rvalue(右值)? 

The C++11 standard generally specifies whether an expression is an lvalue or an rvalue on a case-by-case basis

  通常可以这么归纳:

  • If you can take the address of an expression, the expression is an lvalue.
  • If the type of an expression is an lvalue reference (e.g., T& or const T&, etc.), that expression is an lvalue. 
  • Otherwise, the expression is an rvalue.  Conceptually (and typically also in fact), rvalues correspond to temporary objects, such as those returned from functions or created through implicit type conversions. Most literal values are also rvalues.

 

posted @ 2018-06-08 16:21  P.wang  阅读(303)  评论(0编辑  收藏  举报