【发布时间】:2015-09-14 17:11:43
【问题描述】:
我正在为整数参数的模板特化而苦苦挣扎,也许这根本不可能?
我尝试了什么:
template< int COUNT, typename REMOVE, typename ...T>
struct RemoveFirstElementsImpl
{
using Type= typename RemoveFirstElementsImpl<COUNT-1, T...>::Type;
};
template< typename ...T>
struct RemoveFirstElementsImpl<0, T...>
{
using Type= TypeContainer<T...>;
};
template < int COUNT, typename ... T >
struct RemoveFirstElements
{
using Type = typename RemoveFirstElementsImpl< COUNT, T...>::Type;
};
结果
错误:部分特化并不比主模板更特化,因为它用包扩展替换了多个参数
然后我想到了 SFINAE,例如:
template < int COUNT, typename = typename std::enable_if<COUNT==0>::type, typename HEAD, typename ... T >
struct RemoveFirstElements
{
using Type= TypeContainer<T...>;
};
template < int COUNT, typename = void, typename HEAD, typename ... T >
struct RemoveFirstElements
{
using Type= RemoveFirstElements<COUNT-1, T...>
};
但我不知道如何让参数包和默认参数的组合运行。
也许我走错了路。我想要实现的是获得一个参数列表,其中前 n 个参数从我的 TypeContainer 中删除,这只是一个扩展的 std::tuple。我只需要类型本身而不需要任何参数,我只需要类型而不需要任何对象。
【问题讨论】:
-
请勿丢弃
typename REMOVE -
@DieterLücking 我还在挣扎!你的评论是什么意思。我无法让我的代码再次添加 REMOVE。
-
看@Jarod42的回答
-
好的,抓住重点……!谢谢
标签: c++ templates c++11 c++14 template-specialization