0
我在TMP中編寫一個類來做一些基本的字符串處理。一個字符串被表示爲一個字符類的可變參數模板。我想測試兩個字符串是否相等,如果它們是相關的類型,但我不知道如果在編譯時兩個字符相等,我將如何測試。我目前的代碼如下所示,但不明顯的原因編譯。模板元編程中的匹配變量C++
template <typename T, char firstChar, char... Chrs>
class NamedType
{
public:
typedef T Type;
template <char otherFirst, char... OtherChrs>
class TypeIfMatch
{
};
template <firstChar, char... OtherChrs>
class TypeIfMatch
{
public:
typedef NamedType<T, Chrs>::TypeIfMatch<OtherChars>::type type;
};
template <>
class TypeIfMatch
{
public:
typedef Type type;
};
static const char name[sizeof...(Chrs) + 1];
};
template const char NamedType :: name [sizeof ...(Chrs)+1] = {Chrs ...,'\ 0'};