简短回答 - 不。您不能在 natvis type name 中指定类型限定符、引用等<Type Name="Foo<*>">
。
但:
您可以将模板的 typename 参数用作字符串并与类型进行比较。例如,在节点的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>
因为Foo<short>
你会看到specialization short
和unspecified specialization
其他。
例子:
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;
纳特维斯:
<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>
结果:
或者,如果您在部分专业类型中有一些独特的成员,则可以使用Priority
选项。
例子:
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};
纳特维斯:
<Type Name="Foo<*>">
<DisplayString>partial specialization {baz}</DisplayString>
</Type>
<Type Name="Foo<*>" Priority="Low">
<DisplayString>other specialization</DisplayString>
</Type>
结果: