dimanche 2 septembre 2018

std::find using user defined struct

Im trying to find all possible combos of 5 cards in a standard 52 card deck. I think I've almost got it but I'm getting stuck on one specific if statement. Im trying to figure out if an array is already in a vector, if it isn't I add it in

if (std::find(combos.begin(), combos.end(), combo) != combos.end()){
    std::cout << combos.size() << endl;
    continue;
}
std::cout << combos.size() << endl;
combos.push_back(combo);

combos is a std::vector<std::array<card, 5>> and combo is a std::array<card, 5>. I get the following error with g++

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:677:71: error: 
  invalid operands to binary expression ('const card' and 'const card')
bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}

card is a struct that looks like this

struct card {
    Suit suit;
    int rank;
};

I just don't have any idea of what to do. Thanks for any ideas

Aucun commentaire:

Enregistrer un commentaire