【发布时间】:2020-10-16 16:08:03
【问题描述】:
我正在尝试在 Visual Studio 的构建日志中输出 typedef 的完整类型;即使对于可能失败的 typedef,f.e.当缺少部分专业化时。 我的具体版本是 2019 年,但我也尝试过,但在 2010 年和 2015 年都失败了。
我能找到的唯一可能的解决方案是here,但它在 Visual Studio 中不起作用。
这是测试代码:
template<typename T>
struct Printer;
template <typename T>
struct ST;
template <>
struct ST<int&> {
typedef int T;
};
template <typename T>
struct S {
Printer<typename ST<T>::T> t;
};
int main() {
typedef int& intref;
S<intref> testi;
typedef float& floatref;
S<floatref> testf;
typedef short& shortref;
Printer<shortref> testsi;
}
对于这个例子,我想在某个地方看到一个输出
- "int" 表示现有专业化
- "float&" 表示缺少的专业化
- "short&" 或 "short int&" 用于简单的情况
【问题讨论】:
-
它是visual C++,最好按照预期的方式使用产品。没有人会查看构建日志,他们将鼠标悬停在红色曲线上。其中显示 int&
-
@HansPassant 这是我听过的对“视觉”的最佳解释 :) 我更新了代码以显示曲线的限制。我首先希望“代码分析”能够正确报告类型,并且它确实适用于非常微不足道的情况,但对于目前存在问题的情况却没有。
标签: c++ visual-studio visual-c++ typedef