I have a string and an unordered_map of (string, Object). I already have some code in which I am iterating over the map:
for(auto& item : map) {
do_something;
}
I want to modify it to do the part inside the for loop when the string is non-empty and found inside the map else if string is empty do it for all items in the map.
if(!string.empty()){
item = map.find(string);
do_something;
}
else {
for(auto& item : map) {
do_something;
}
}
Can I do this without rewriting the do_something or creating a separate function?