SFINAE Constructors [duplicate]

这一生的挚爱 提交于 2019-12-01 19:50:39

Use a non-type template parameter instead:

template <class Integer,
    std::enable_if_t<std::is_integral<Integer>::value, int> = 0>
T(Integer n) {
    // ...
}

template <class Float,
    std::enable_if_t<std::is_floating_point<Float>::value, int> = 0>
T(Float n) {
    // ...
}

This works because the compiler has to substitute the first template parameter before it can determine the type of the value parameter.

One way to fix this is to add extra , typename=void arguments so that none of the overloads has the same number of template parameters.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!