【发布时间】:2020-08-30 09:42:49
【问题描述】:
出于调试目的,我想查看在 c++ 中解压缩可变参数模板的结果。在VS中无论如何都可能吗?
//variadic template
template<class ... Ts>
void foo(Ts...args)
{
//...some code
auto x = bar(args..);
}
//client code:
foo(std::string("123"),int(4),5.6f);
我认为代码生成的结果会被解压成这样的:
void foo<std::string, int, float>(std::string args1, int args2, float args3)
{
//...some code
auto x = bar(args1,args2,args3);
}
但如果它更难一点,谁知道它会解压成什么? :) 在尝试找到它之前,我认为如果在 VS 中将“属性->C/C++->预处理器->预处理到文件”切换为“是”,它将在预处理期间生成,我们可以看到这一点。但不是,在这个阶段它只适用于标题,#incldude's #define's ... 问题是如何查看解包参数包代码生成的结果?这段代码是否以可读的形式存在?或者结果翻译成二进制和*.exe文件?
【问题讨论】:
-
不确定VS能不能做到这一点,但你们cppinsights可以:cppinsights.io/s/00cd7215
-
是的!这正是我所需要的。我无法想象 VS 中缺少这个“必须具备的功能”。
标签: c++ visual-studio visual-studio-2019 variadic-functions visual-studio-debugging