Skip to content

Instantly share code, notes, and snippets.

@mrvn
Created January 11, 2019 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrvn/fba5c959e208e6f321917b2fbab1ecfd to your computer and use it in GitHub Desktop.
Save mrvn/fba5c959e208e6f321917b2fbab1ecfd to your computer and use it in GitHub Desktop.
testing if auto uses refs
#include <vector>
#include <iostream>
struct Foo {
Foo() : x(0) { };
int x;
};
int main() {
std::vector<Foo> v(5);
for (auto c : v) { std::cout << c.x << " "; }
std::cout << std::endl;
for (auto c : v) { c.x++; }
for (auto c : v) { std::cout << c.x << " "; }
std::cout << std::endl;
for (auto & c : v) { c.x++; }
for (auto & c : v) { std::cout << c.x << " "; }
std::cout << std::endl;
}
mrvn@frosties:~% ./auto
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment