使用auto 编译器会自动帮我们根据右值进行推导出左值的类型。在推导的过程中,编译器会自动把顶层const 去掉,存在底层const ,底层const 会保留。
int i = 5;
const int ci = i, &cr = i;
auto b1 = i; //类型为 int
auto b2 = cr; //类型为 int
auto b3 = &ci; // 类型为 const int *
decltype
decltype 会根据 表达式 返回的类型进行声明, decltype 不会去掉顶层cosnt ,且dectype作用于引用时其类型为引用,在 auto 是根据引用值得类型,
当decltype((var))结果永远是引用,而 decltype(var) 则看 var 是引用其类型才是引用。