Any reason to not use auto& for C++ range-based for-loops?
c++
Solution
The two code snippets will result in the same code being generated: with `auto`, the compiler will figure out that the underlying type is `int`, and do exactly the same thing.
However, the option with `auto` is more "future-proof": if at some later date you decide that `int` should be replaced with, say, `uint8_t` to save space, you wouldn't need to go through your code looking for references to the underlying type that may need to be changed, because the compiler will do it for you automatically.
Problem
For example, the loop: ``` std::vector<int> vec; ... for (auto& c : vec) { ... } ``` will iterate over vec and copy each element by reference. Would there ever be a reason to do this? ``` for (int& c : vec) { ... } ```