[英]C++ Partial Template Specialization and Natvis
I'm trying to create Visual Studio debug visualizers for a partially specialized type.我正在尝试为部分专业化类型创建 Visual Studio 调试可视化工具。 For example, let's say I have something like this:
例如,假设我有这样的事情:
template <typename T>
struct Foo
{
T bar;
};
template <typename T>
struct Foo<T*>
{
T baz;
};
Without the partial specialization, this would be easy:如果没有部分专业化,这将很容易:
<Type Name="Foo<*>"> ... </Type>
With full specialization, it'd also be easy:有了完全的专业化,这也很容易:
<Type Name="Foo<int>"> ... </Type>
But how do I cover the partial specialization?但是我如何涵盖部分专业化? Is this even supported?
这甚至被支持吗? If not, is there a workaround?
如果没有,是否有解决方法?
Short answer - No. You can't specify type qualifiers, references, and so on in natvis type name <Type Name="Foo<*>">
.简短回答 - 不。您不能在 natvis 类型名称
<Type Name="Foo<*>">
中指定类型限定符、引用等。
But:但:
You can use the template's typename parameter as a string and compare with a type.您可以将模板的 typename 参数用作字符串并与类型进行比较。 For example, in the node's
Condition
attribute:例如,在节点的
Condition
属性中:
<Type Name="Foo<*>">
<DisplayString Condition="strcmp("$T1","short")==0">specialization short</DisplayString>
<DisplayString Condition="strcmp("$T1","int &")==0">specialization int &</DisplayString>
<DisplayString>unspecified specialization</DisplayString>
</Type>
For Foo<short>
you will see specialization short
and unspecified specialization
for other.对于
Foo<short>
,您将看到其他的specialization short
和unspecified specialization
。
Example:例子:
template <typename T, typename U>
struct Foo
{
T bar;
};
template <typename U>
struct Foo<int &, U>
{
U baz;
};
int main()
{
int gg = 0;
Foo<short, int> a;
Foo<int, int> b;
Foo<int &, int> c;
Natvis:纳特维斯:
<Type Name="Foo<*,*>" >
<DisplayString Condition="strcmp("$T1","short")==0">specialization short</DisplayString>
<DisplayString>unspecified specialization</DisplayString>
</Type>
<Type Name="Foo<int&,*>">
<DisplayString>partial specialization int&</DisplayString>
</Type>
Result:结果:
Or you, if you have some unique member in your partially specialized type, can use Priority
option.或者,如果您的部分专业类型中有一些独特的成员,则可以使用
Priority
选项。
Example:例子:
template <typename T>
struct Foo
{
T bar;
};
template <typename U>
struct Foo<U &>
{
U baz;
};
int main()
{
int g = 0;
Foo<short> a;
Foo<int> b;
Foo<int &> c{g};
Natvis:纳特维斯:
<Type Name="Foo<*>">
<DisplayString>partial specialization {baz}</DisplayString>
</Type>
<Type Name="Foo<*>" Priority="Low">
<DisplayString>other specialization</DisplayString>
</Type>
Result:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.