Is there an efficient way of executing a function if any string inside a vector contains a substring?
Something along these lines
if(vector.contains(strstr(currentVectorElement,"substring"))) {
//do something
}
if(vector.contains(strstr(currentVectorElement,"substring2"))) {
//do something else
}
The only thing I can think of is iterating over each string and check if the substring exists.
std::find_if
as mentioned below, you still loop over all elements. You would have to use something other than a vector. If you were not looking for substrings, but could compare the whole string, you could use anunordered_map
, but with substrings it's difficult...