Usually I don't care about the value of the item in the set, I care only whether or not it exists. And repeatedly writing if (s.find(val) == s.end())
is long, ugly and less readable.
Is there a nice way which looks like if (contains(s,val))
, which is somewhat standard (stl, boost).
Bonus point for a solution that works for maps as well.
Yes, I know I can
#define has(X,Y) (X).find(Y) != (X).end()
template<T,U> inline bool has(T s,U elt) {return s.find(elt) != s.end();}
but I'd rather use a best practice than reinventing a lot of small utilities.