您可以专门化结构/类而不是专门化功能:根据您的情况调整以下内容(http://ideone.com/VgIJfj):
namespace details
{
template<std::size_t I = 0, typename FuncT, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type
for_each(const std::tuple<Tp...> &, FuncT)
{ }
template<std::size_t I = 0, typename FuncT, typename... Tp>
inline typename std::enable_if<I < sizeof...(Tp), void>::type
for_each(const std::tuple<Tp...>& t, FuncT f)
{
f(std::get<I>(t));
for_each<I + 1, FuncT, Tp...>(t, f);
}
template <typename T>
struct traverseType
{
void operator () (const T& t) const
{
std::cout << "it is a generic T:" << t << std::endl;
}
};
template <>
struct traverseType<int>
{
void operator () (int i) const
{
std::cout << "it is a int:" << i << std::endl;
}
};
// needed by the for_each.
struct traverseTypeCaller
{
template <typename T>
void operator () (const T& t) const
{
details::traverseType<T>()(t);
}
};
template <typename ...T>
struct traverseType<std::tuple<T...>>
{
void operator () (const std::tuple<T...>& t) const
{
std::cout << "it is a tuple:" << std::endl;
for_each(t, traverseTypeCaller());
}
};
}
template <typename T>
void traverseType(const T& t)
{
details::traverseTypeCaller()(t);
}