我从这里实现了元组:https : //voidnish.wordpress.com/2013/07/13/tuple-implementation-via-variadic-templates/
可以使用NATVIS对其进行可视化吗?我到了
<Type Name="tuple">
<DisplayString>()</DisplayString>
</Type>
<Type Name="tuple<*>">
<DisplayString>({_Myfirst})</DisplayString>
</Type>
Run Code Online (Sandbox Code Playgroud)
如何获取多个类型的_Myfirst值,以获取
<Type Name="tuple<*,*>">
<DisplayString>({_Myfirst}, {???})</DisplayString>
</Type>
<Type Name="tuple<*,*,*>">
<DisplayString>({_Myfirst}, {???}, {???})</DisplayString>
</Type>
Run Code Online (Sandbox Code Playgroud)
等等?
您必须对类型进行一些修改才能使其正常工作。所需要的是一个base_typetypedef。
即
// tuple
template<class... _Types> class tuple;
// empty tuple
template<> class tuple<> {};
// recursive tuple definition
template<class _This,
class... _Rest>
class tuple<_This, _Rest...>
: private tuple<_Rest...>
{
public:
typedef tuple<_Rest...> base_type; // ***** Added this line
_This _Myfirst;
};
Run Code Online (Sandbox Code Playgroud)
现在,我们可以使用natvis声明来递归评估基本类型:
<!-- Handle empty tuples -->
<Type Name="tuple<>">
<DisplayString>()</DisplayString>
<Expand/>
</Type>
<!-- Handle a single parameter (this is also our terminator for recursion) -->
<Type Name="tuple<*>">
<DisplayString IncludeView="noparens">{_Myfirst}</DisplayString>
<DisplayString ExcludeView="noparens">({_Myfirst})</DisplayString>
<Expand>
<Item Name="Value">_Myfirst</Item>
</Expand>
</Type>
<!-- Handle 2 or more items -->
<Type Name="tuple<*,*>">
<!-- show the first item and then recurse by casting this to 'base_type' -->
<DisplayString IncludeView="noparens">{_Myfirst}, {*(base_type *)this,view(noparens)}</DisplayString>
<!-- Wrap our display string that doesn't a have any parentheses, this will be only done for the top level tuple -->
<DisplayString ExcludeView="noparens">({*this,view(noparens)})</DisplayString>
<Expand>
<!-- Show the top level item -->
<Item Name="Value">_Myfirst</Item>
<!-- Recursively expand our base types -->
<ExpandedItem>*(base_type *)this</ExpandedItem>
</Expand>
</Type>
Run Code Online (Sandbox Code Playgroud)
结果如下:
| 归档时间: |
|
| 查看次数: |
388 次 |
| 最近记录: |