在llvm代码中,我找到了这个代码示例:
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
找到此代码答案 0 :(得分:0)
好的,感谢评论,我明白了!我很愚蠢:好像但是这次类型是TagT而不是int。这很令人困惑,因为模板的类型本身就是模板类型......但是好的!