Of course, the real question is: why such an arbitrary restriction?
I find it completely normal to have the same type as the key and value, so instead of providing an ambiguous operator overload, perhaps you could just provide two different methods?
ValueType const& by_key(KeyType const&) const; KeyType const& by_value(ValueType const&) const;
and run with it.
EDIT . Following @Georg Fritzsche's comment :)
Remember that one of the basic rules of overloading is that all overloads should have the same basic meaning.
source share