2017-05-31 72 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。這很混亂,因爲模板的類型本身就是一個模板類型......但是好的!