You can't do this with std::set
, because std::set<>::find
is
not a (member) template; the argument must be of the key type.
For simple classes like yours, it's likely that using an
std::vector<A>
and keeping it sorted (using std::lower_bound
for lookup, and as the insertion point) will be just as fast.
And with std::lower_bound
, you can pass in a comparitor, and
use any type you want as key. All you have to do is ensure that
your comp
class can handle the mixed type comparisons, e.g.:
struct Comp
{
bool operator()( A const&, B const& ) const;
bool operator()( A const&, int ) const;
bool operator()( int, A const& ) const;
};