如何在Xcode调试器中查看推断出的模板类型?
使用Meyers'中第1项的例子。 Effective Modern C ++(2015),注意变量的值及其类型在Xcode"变量视图中是如何显示的,"但是没有办法看到变量T的结果推论。
是否可以在Xcode调试器中看到推导出的T类型?
我的老板给了我typeId
,如下所示,但我希望直接在调试器中看到该类型。此外,此命令会在IDE之间产生不一致的结果;例如,Xcode输出" i"对于int,而Visual Studio输出" int。"
完整的可执行文件和输出如下所示。 Thx,Keith:^)
Xcode屏幕截图
最小,完整且可验证的示例:
#include <iostream>
template <typename T>
int case1a(T& param) {
return param;
}
template <typename T>
int case1b(const T& param) {
std::cout << "Type ID : " << typeid(T).name() << std::endl;
std::cout << "Type param: " << typeid(param).name() << std::endl;
return param;
}
template <typename T>
int case2(T&& param) {
return param;
}
template <typename T>
int case3(T param) {
return param;
}
int main() {
int a(23);
const int ar(a);
const int & car = a;
float b(7.);
std::cout << "case1a(a): " << case1a(a) << std::endl;
std::cout << "case1a(ar): " << case1a(ar) << std::endl;
std::cout << "case1a(car): " << case1a(car) << std::endl;
std::cout << "case1b(a): " << case1b(a) << std::endl;
std::cout << "case1b(ar): " << case1b(ar) << std::endl;
std::cout << "case1b(car): " << case1b(car) << std::endl;
std::cout << "case1b(b): " << case1b(b) << std::endl;
std::cout << "case2(a): " << case2(a) << std::endl;
std::cout << "case2(ar): " << case2(ar) << std::endl;
std::cout << "case2(car): " << case2(car) << std::endl;
std::cout << "case3(a): " << case3(a) << std::endl;
std::cout << "case3(ar): " << case3(ar) << std::endl;
std::cout << "case3(car): " << case3(car) << std::endl;
std::cout << std::endl;
return 0;
}
输出
case1a(a): 23
case1a(ar): 23
case1a(car): 23
case1b(a): Type ID : i
Type param: i
23
case1b(ar): Type ID : i
Type param: i
23
case1b(car): Type ID : i
Type param: i
23
case1b(b): Type ID : f
Type param: f
7
case2(a): 23
case2(ar): 23
case2(car): 23
case3(a): 23
case3(ar): 23
case3(car): 23
Program ended with exit code: 0