我注意到在c ++ 17中binary_function被删除了。我不知道如何解决它。有人可以帮我改变结构吗?谢谢
我尝试通过谷歌搜索但找不到解决方案。Visual Studio 2019,C++17
struct FGuildCompare : public std::binary_function<CGuild*, CGuild*, bool>
{
bool operator () (CGuild* g1, CGuild* g2) const
{
if (g1->GetLadderPoint() < g2->GetLadderPoint())
return true;
if (g1->GetLadderPoint() > g2->GetLadderPoint())
return false;
if (g1->GetGuildWarWinCount() < g2->GetGuildWarWinCount())
return true;
if (g1->GetGuildWarWinCount() > g2->GetGuildWarWinCount())
return false;
if (g1->GetGuildWarLossCount() < g2->GetGuildWarLossCount())
return true;
if (g1->GetGuildWarLossCount() > g2->GetGuildWarLossCount())
return false;
int c = strcmp(g1->GetName(), g2->GetName());
if (c>0)
return true;
return false;
}
};
Run Code Online (Sandbox Code Playgroud)
std::binary_function 已删除
基本上如何使以下代码编译?
我知道它失败了,因为编译器试图评估类似的东西,([](int &i){})(0)但是如何解决该问题呢?
template <class TElement>
struct foo {
TElement _e;
foo(TElement e) : _e(e){}
template <class Lambda>
void bar(Lambda f) {
using TResult = decltype(std::declval<Lambda>()(std::declval<TElement>()));
}
};
int main() {
foo<int>(0).bar([](int i){}); // compile
foo<int>(0).bar([](int &&i){}); // compile
foo<int>(0).bar([](int const &i){}); // compile
foo<int>(0).bar([](int &i){}); // failed
}
Run Code Online (Sandbox Code Playgroud)