我正在编写一个模板整数包装类,我想根据类的模板参数类型提供一个赋值运算符:
template<typename IntType>
class secure_int {
public:
// enable only if boost::is_signed<IntType>
secure_int &operator=(intmax_t value) {
// check for truncation during assignment
}
// enable only if boost::is_unsigned<IntType>
secure_int &operator=(uintmax_t value) {
// check for truncation during assignment
}
};
因为 operator= 不是成员模板,所以带有 boost::enable_if_c 的 SFINAE 将不起作用。提供此类功能的工作选项是什么?