相关疑难解决方法(0)

如何将binary_function更改为c++17代码?

我注意到在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 已删除

refactoring visual-studio c++17

4
推荐指数
1
解决办法
1689
查看次数

如何正确找出lambda的返回类型

基本上如何使以下代码编译?

我知道它失败了,因为编译器试图评估类似的东西,([](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)

c++ c++11

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

标签 统计

c++ ×1

c++11 ×1

c++17 ×1

refactoring ×1

visual-studio ×1