I have 2 pieces of code that look similar and I want to make use of templates to prevent copied code.
if(!myVector.empty()) {
for(auto& i : myVector)
{
std::cout << i << std::endl;
//some other code that is similar to below
}
}
if(!myUnorederedMap.empty()) {
for(auto i : myUnorderedMap)
{
std::cout << i.second << std::endl;
//some other code that is similar to top
}
}
How do I write a function template for the iterators when I have to call .second on my map but not my vector?