使用 gcc 4.7.3,我收到以下错误
prog.cpp:在函数'int main()'中:prog.cpp:27:63:错误:'Erase >::Result'尚未声明
使用此代码:
template <typename... List>
struct TypeList
{
enum
{
Length = sizeof...(List)
};
};
template <typename ToErase, typename... List>
struct Erase;
template <typename ToErase>
struct Erase<ToErase, TypeList<>>
{
typedef TypeList<> Result;
};
template <typename ToErase, typename... Head, typename... Tail>
struct Erase<ToErase, TypeList<Head..., ToErase, Tail...>>
{
typedef TypeList<Head..., Tail...> Result;
};
int main()
{
static_assert(Erase<double, TypeList<int, double, char>>::Result::Length == 2,
"Did not erase double from TypeList<int, double, char>");
return 0;
}
鉴于我收到的错误消息,我不明白为什么代码无法编译,因为类似的情况确实可以干净地编译:
template <typename ToAppend, typename... List>
struct Append;
template <typename ToAppend, typename... List>
struct Append<ToAppend, TypeList<List...>>
{
typedef TypeList<List..., ToAppend> Result;
}
template <typename... ToAppend, typename... List>
struct Append<TypeList<ToAppend...>, TypeList<List...>>
{
typedef TypeList<List..., ToAppend...> Result;
}
标准中是否有关于无法推断出两个参数包中间的元素的引用,就像我试图对第一个代码块做的那样?