【发布时间】:2017-04-09 12:47:32
【问题描述】:
以下2个有什么区别:
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
explicit Approx(const T& value) {}
对
template <typename T>
explicit Approx(const typename std::enable_if<std::is_constructible<double, T>::value, T>::type& value) {}
Approx 是普通类(未模板化)的构造函数,我需要可以从 double 构造的类型
我的问题是第一个有效,但不是 C++98(默认模板参数等 - 我对 enable_if 和 is_constructible 有自己的 c++98 特征)
我问的原因是因为我想支持double 的强类型定义:
class Volatility {
double underlying_;
public:
explicit Volatility(double u) : underlying_(u) {}
explicit operator double() const { return underlying_; }
};
Approx(Volatility(1.)); // error
【问题讨论】:
标签: c++ templates sfinae c++03 c++98