我希望通过使用 BOOST_STATIC_ASSERT 来帮助使用我的一些模板代码的用户,让他们知道他们使用了一个不兼容的类型,其编译错误消息比当前使用不兼容类型生成的怪物更简单。
该示例有点太复杂,无法在此处重现,但希望这能捕获我想要的本质:
我的问题是如何格式化最后一行“模板模板”?
template <typename P1, int P2, typename P3>
class InterestingType
{
}
template<typename T>
struct is_interesting_type{
static const bool value = false;
};
template<template<typename,int,typename> typename InterestingType> //No idea how to format this..
struct is_interesting_type{
static const bool value = true;
};
最佳答案
将代码改为
template <typename P1, int P2, typename P3>
struct is_interesting_type<InterestingType<P1, P2, P3> >{
static const bool value = true;
};
关于模板化类型的 C++ 模板特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3098983/