小编a_p*_*han的帖子

如何在C ++中检查编译时是否存在特定的运算符重载?

我有一个类,它为多个输入类型重载了()运算符

struct Type {
    void operator()(int);
    void operator()(std::string);
};
Run Code Online (Sandbox Code Playgroud)

现在,我想使用SFINAE来检查()运算符是否存在特定的重载,即

if (Type()(std::string) overload exists) {
    // do something...
}
Run Code Online (Sandbox Code Playgroud)

在C ++ 11中可以做到吗?(我不能使用C ++ 14或C ++ 17)。

注意:在实际代码中,有一个模板类,该类接受具有某些属性的类类型。该模板中有一个成员函数,该成员函数将根据是否存在参数类型的()运算符的某些特定重载进行专门化。

c++ templates sfinae c++11

3
推荐指数
1
解决办法
92
查看次数

标签 统计

c++ ×1

c++11 ×1

sfinae ×1

templates ×1