【问题标题】:Is it possible to NATVIS a recursive tuple (variadic template)?是否可以 NATVIS 递归元组(可变参数模板)?
【发布时间】:2016-04-20 12:28:18
【问题描述】:

我从这里实现了元组:https://voidnish.wordpress.com/2013/07/13/tuple-implementation-via-variadic-templates/

是否可以使用 NATVIS 将其可视化?我做到了

<Type Name="tuple">
  <DisplayString>()</DisplayString>  
</Type>

<Type Name="tuple&lt;*&gt;">
  <DisplayString>({_Myfirst})</DisplayString>
</Type>

如何获取多个类型的 _Myfirst 值,以获取

<Type Name="tuple&lt;*,*&gt;">
  <DisplayString>({_Myfirst}, {???})</DisplayString>
</Type>

<Type Name="tuple&lt;*,*,*&gt;">
  <DisplayString>({_Myfirst}, {???}, {???})</DisplayString>
</Type>

等等?

【问题讨论】:

    标签: natvis


    【解决方案1】:

    您必须稍微修改类型才能使其正常工作。需要的是base_type typedef。

    // 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;
    };
    

    现在我们可以使用 natvis 声明递归地评估基本类型:

    <!-- Handle empty tuples -->
    <Type Name="tuple&lt;&gt;">
        <DisplayString>()</DisplayString>
        <Expand/>
    </Type>
    
    <!-- Handle a single parameter (this is also our terminator for recursion) -->
    <Type Name="tuple&lt;*&gt;">
        <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&lt;*,*&gt;">
        <!-- 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>
    

    结果如下:

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      • 2013-03-17
      相关资源
      最近更新 更多