#include <iostream>
#include <vector>
using namespace std;
struct Bar {
Bar() = default;
Bar(const Bar &) {
cout << "Copying bar\n";
}
};
void foo1(const Bar &a) {
cout << "Executing foo1\n";
[a] {
cout << "Executing lambda1\n"; }();
}
void foo2(const Bar &a) {
cout << "Executing foo2\n";
[&a] {
cout << "Executing lambda2\n"; }();
}
int main() {
std::vector<Bar> bars(2);
foo1(bars[0]);
for (const Bar& b : bars) {
foo2(b);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEJhciB7CglCYXIoKSA9IGRlZmF1bHQ7CglCYXIoY29uc3QgQmFyICYpIHsKCQljb3V0IDw8ICJDb3B5aW5nIGJhclxuIjsKCX0JCn07Cgp2b2lkIGZvbzEoY29uc3QgQmFyICZhKSB7CiAgICBjb3V0IDw8ICJFeGVjdXRpbmcgZm9vMVxuIjsKCVthXSB7Cgljb3V0IDw8ICJFeGVjdXRpbmcgbGFtYmRhMVxuIjsgfSgpOwp9Cgp2b2lkIGZvbzIoY29uc3QgQmFyICZhKSB7CiAgICBjb3V0IDw8ICJFeGVjdXRpbmcgZm9vMlxuIjsKCVsmYV0gewoJY291dCA8PCAiRXhlY3V0aW5nIGxhbWJkYTJcbiI7IH0oKTsKfQoKaW50IG1haW4oKSB7CglzdGQ6OnZlY3RvcjxCYXI+IGJhcnMoMik7Cglmb28xKGJhcnNbMF0pOwoJZm9yIChjb25zdCBCYXImIGIgOiBiYXJzKSB7CgkgZm9vMihiKTsKCX0KCXJldHVybiAwOwp9