The typical way to check for existence in many STL containers such as std::map
, std::set
, … is:
const bool is_in = container.find(element) != container.end();
More Related Contents:
- C++ std::set update is tedious: I can’t change an element in place
- what happens when you modify an element of an std::set?
- How to update an existing element of std::set?
- Does boost have a datatype for set operations that is simpler than the STL?
- Is the std::set iteration order always ascending according to the C++ specification?
- stl::map assert [closed]
- How can I use std::maps with user-defined types as key?
- std::vector::resize() vs. std::vector::reserve()
- What requirements must std::map key classes meet to be valid keys?
- How to find if a given key exists in a C++ std::map
- How to get std::vector pointer to the raw data?
- Can standard container templates be instantiated with incomplete types?
- Sort list using STL sort function
- What does the standard library guarantee about self move assignment?
- How to declare a vector of atomic in C++
- How to filter items from a std::map? [duplicate]
- Is the use of std::vector objects in C++ acceptable, or should I use an alternative?
- std::optional specialization for reference types
- How to iterate over a priority_queue?
- use std::fill to populate vector with increasing numbers
- What is the default hash function used in C++ std::unordered_map?
- Can we use a user defined class for the key in a STL map?
- What happens when you call data() on a std::vector?
- STL analogue in Fortran
- How to use the priority queue STL for objects?
- std::vector reserve() and push_back() is faster than resize() and array index, why?
- std::mutex performance compared to win32 CRITICAL_SECTION
- Vector Iterators Incompatible
- Should you overload swap in the std namespace?
- what does `using std::swap` inside the body of a class method implementation mean?