我尝试编写一个IsLast类型特征来检查给定类型是否是a中的最后一个std::tuple,但下面的代码不能编译.我知道如何绕过它,但我很好奇为什么编译器不喜欢它.我猜我必须对variadic-template的特化有一些规则,我不知道.
代码位于:https://godbolt.org/g/nXdodx
错误信息:
error: implicit instantiation of undefined template
'IsLast<std::tuple<std::__cxx11::basic_string<char>, int>, int>'
Run Code Online (Sandbox Code Playgroud)
专业化声明也有警告:
警告:类模板部分特化包含无法推导的模板参数; 永远不会使用这种部分专业化
#include <tuple>
#include <string>
/////////This works
template<typename TP, typename T>
struct IsFirst;
template<typename U, typename ...V, typename T>
struct IsFirst <std::tuple<U, V...>, T>
{
enum {value = false};
};
template<typename U, typename ...V>
struct IsFirst <std::tuple<U, V...>, U>
{
enum {value = true};
};
////////This doesn't compile
template<typename TP, typename T>
struct IsLast;
template<typename ...U, typename V, typename …Run Code Online (Sandbox Code Playgroud) c++ template-specialization template-meta-programming variadic-templates c++11