使用SFINAE的同一模板构造函数的两种不同实现

时间:2017-09-03 09:17:55

标签: c++11 constructor overloading sfinae

是否有可能通过SFINAE启用两个不同的构造函数,具体取决于特征?我尝试了以下方法,但没有成功。

template<typename... Args>
class Foo
{
public:
    template<typename F,
    typename FunTrait = typename std::enable_if<std::is_convertible<F, std::function<void(Args...)>>::value>::type>
    Foo(F&& func)
    {
       //Do one thing
    }


    template<typename F,
    typename FunTrait = typename std::enable_if<!std::is_convertible<F, std::function<void(Args...)>>::value>::type>
    Foo(F&& func)
    {
       //Do another thing
    }
};

Foo<int> someFoo([](){});

这告诉我构造函数已在第二个构造函数上定义,但它们不能同时为单个类型的F启用。

0 个答案:

没有答案
相关问题