fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct Bar {
  6. Bar() = default;
  7. Bar(const Bar &) {
  8. cout << "Copying bar\n";
  9. }
  10. };
  11.  
  12. void foo1(const Bar &a) {
  13. cout << "Executing foo1\n";
  14. [a] {
  15. cout << "Executing lambda1\n"; }();
  16. }
  17.  
  18. void foo2(const Bar &a) {
  19. cout << "Executing foo2\n";
  20. [&a] {
  21. cout << "Executing lambda2\n"; }();
  22. }
  23.  
  24. int main() {
  25. std::vector<Bar> bars(2);
  26. foo1(bars[0]);
  27. for (const Bar& b : bars) {
  28. foo2(b);
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Executing foo1
Copying bar
Executing lambda1
Executing foo2
Executing lambda2
Executing foo2
Executing lambda2