fulmicoton fulmicoton - 1 year ago 77
C++ Question

How to check that an element is in a std::set?

How do you check that an element is in a set?

Is there a simpler equivalent of the following code:

myset.find(x) != myset.end()

Answer Source

The typical way to check for existence in many STL containers is:

const bool is_in = container.find(element) != container.end();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download