user11114606
user11114606

Reputation:

How to change binary_function to c++17 code?

I noticed that in c ++ 17 binary_function was deleted. And I have no idea how to solve it instead. Could somebody help me what to change the structure? Thank you

I tried searching through google but couldn't find a solution. 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;
    }
};

std::binary_function removed

Upvotes: 4

Views: 2073

Answers (1)

Marshall Clow
Marshall Clow

Reputation: 16680

All std::binary_function added were three typedefs; and (in many cases) those types can now be deduced. Just remove the inheritance from std::binary_function.

If you need the code to still work pre-C++17, add these to your class:

    typedef CGuild*   first_argument_type;
    typedef CGuild*   second_argument_type;
    typedef bool      result_type;

Upvotes: 6

Related Questions