what\'s the alternative?
Should I write by myself?
There is the std::find()
algorithm, which performs a linear search over an iterator range, e.g.,
std::vector v;
// Finds the first element in the vector that has the value 42:
// If there is no such value, it == v.end()
std::vector::const_iterator it = std::find(v.begin(), v.end(), 42);
If your vector is sorted, you can use std::binary_search()
to test whether a value is present in the vector, and std::equal_range()
to get begin and end iterators to the range of elements in the vector that have that value.