2017-05-31 70 views
-1

在LLVM代码,我发现这个代码示例:两种类型的模板里面(?字)在C++

template <typename TagT, typename... MemberTs> class PointerSumType { 
    uintptr_t Value; 

    typedef detail::PointerSumTypeHelper<TagT, MemberTs...> HelperT; 

public: 
    PointerSumType() : Value(0) {} 

    /// A typed constructor for a specific tagged member of the sum type. 
    template <TagT N> 
    static PointerSumType 
    create(typename HelperT::template Lookup<N>::PointerT Pointer) { 
    PointerSumType Result; 
    void *V = HelperT::template Lookup<N>::TraitsT::getAsVoidPointer(Pointer); 
    assert((reinterpret_cast<uintptr_t>(V) & HelperT::TagMask) == 0 && 
      "Pointer is insufficiently aligned to store the discriminant!"); 
    Result.Value = reinterpret_cast<uintptr_t>(V) | N; 
    return Result; 
    } 

    TagT getTag() const { return static_cast<TagT>(Value & HelperT::TagMask); } 

    template <TagT N> bool is() const { return N == getTag(); } 
    //..... 
}; 

我的问题是:什么意思template <TagT N>,怎么可能有内部的两个词模板?

谢谢,如果你花时间回答我。

P.S.你可以在http://llvm.org/docs/doxygen/html/PointerSumType_8h_source.html

+2

'template '也是两个单词。怎么可能没有两个字? – melpomene

+3

它是__非模板参数___ – Danh

回答

0

找到这个代码好的,感谢意见,我明白了!我是愚蠢的:就像这次是类型是TagT,而不是int。这很混乱,因为模板的类型本身就是一个模板类型......但是好的!