4 For an expression e, the type denoted by decltype(e) is defined as follows:
(4.1) — if e is an unparenthesized id-expression or an unparenthesized class member access (5.2.5), decltype(e)
is the type of the entity named by e. If there is no such entity, or if e names a set of overloaded functions, the program is ill-formed;
(4.2) — otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e;
(4.3) — otherwise, if e is an lvalue, decltype(e) is T&, where T is the type of e;
(4.4) — otherwise, decltype(e) is the type of e.
只有返回(左值或右值)引用,才有可能区分表达式返回的结果是左值还是右值。
#include <type_traits>
std::remove_reference<decltype(*p)>::type a;