'C++ - Is it better to use references in for loops?
If I have something like this :vector<string> v{"lorem", "ipsum"};
Is it better to do my loop like this :for(string s : v){ ... }
or like this :for(string &s : v){ ... }
So my question is, does this type of loop duplicate the data (and so it's better to use a reference) or not ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
