【发布时间】:2014-02-04 09:21:18
【问题描述】:
我有以下问题。在模板中,我想检查类型是否是给定类型之一。
代码说明:
tempalte <typename T>
class foo
{
public:
//BOOST_STATIC_ASSERT(T is one of int, long, long long, double ....);
//boost::is_scalar doesn't fill my requirements since I need
//to provide my own list of types
};
我知道如何使用模板规范来做到这一点,但这种方式很乏味。
template <typename T>
class ValidateType
{
static const bool valid = false;
};
template <>
class ValidateType<int>
{
static const bool valid = true;
}
//repeat for every wanted type
有没有优雅的方法?
【问题讨论】: