I'm having a bit of an issue with custom sorting strings. What I basically have is an std::list of std::pair, whose elements are enum class and std::string. Enum is for colours (those do sort correctly) and strings contain numbers in [2, 10] interval, with additions of letters J, Q, K and A, respectively. As you may have already guessed, it's a deck of cards, that must look like this after sorting:
2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A.
What should my lambda function look like in order to achieve this? Or is there another way?
This is what I've compe up with so far:
enum class Colours
{
Spades, Clubs, Hearts, Diamonds
};
typedef std::list<std::pair<Colours, std::string>> Deck;
typedef std::pair<Boje, std::string> Pair;
And here's the actual sorting:
deck.sort( [] (const Pair &x, const Pair &y) -> bool {
if(x.first == y.first) return x.second < y.second;
else return x.first < y.first;
} );
And the current sorting result: 10 2 3 4 5 6 7 8 9 A J K Q