Every now and then, I see something like this in my product's code base:
void ProcessDirectories(const std::vector<std::string>& paths)
{
for (auto&& path : paths)
{
// Do something with path
}
}
I would have expected this line instead:
for (auto& path : paths)
Where path
is a normal reference to the item in the collection being enumerated.
But what does this the "double ampersand thing" imply in the enumeration
for (auto&& path : paths)
I understand this to be called access by forwarding reference But what does it provide for a collection of strings? I understand the basics of R-values and move semantics, but I don't admit expertise here.
Or perhaps a more general question if a collection of strings is uninteresting for the different type of reference enumerations: When is it appropriate to enumerate over a collection by forwarding reference?