现代C++之理解decltype
现代C++之理解decltype decltype用于生成变量名或者表达式的类型,其生成的结果有的是显而易见的,可以预测的,容易理解,有些则不容易理解。大多数情况下,与使用模板和auto时进行的类型推断相比,decltype作用于变量名或者表达式只是重复了一次变量名或者表达式的确切类型: const int i = 0; // decltype(i) 为 const int bool f(const Widget& w); // decltype(w) 为 const Widget& // decltype(f) 为 bool(const Widget&) struct Point { int x, y; // decltype(Point::x) 为 int }; // decltype(Point::y) 为 int Widget w; // decltype(w) 为 Widget if (f(w)) … // decltype(f(w)) 为 bool template<typename T> // std::vector 的简易实现 cla...