'Iterate over two possible types of iterable objects C++
I'd like a program of mine to be flexible and for it to either be able to iterate over a list of files in a directory for which I'm currently using
for(const auto& dirEntry : fs::directory_iterator(input_dir))
where fs is filesystem. I'd also like the possibility of iterating over a vector of strings, and to choose between these two different types at runtime. however my best idea so far is to just have two different for loops and choosing the correct one with an if/else statement but that feels like a poor coding choice. Is there any way to generically iterate over one or the other?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
