By default, std::lower_bound
uses the less-than operator for the type behind the iterators. By defining your own operator <
, lower_bound should just do the right thing. i.e. calling it like this
std::lower_bound(m_cards.begin(), m_cards.end(), card);
should work fine, give an appropriate operator <
defined on card types.
One thing to point out is your code for operator <
can be simplified to
friend bool operator< (const Card& lhs, const Card& rhs)
{
return lhs.m_Suit < rhs.m_Suit ||
(lhs.m_Suit == rhs.m_Suit && lhs.m_Rank < rhs.m_Rank);
}
(which also fixes a subtle bug in your code).