Skip to content

Instantly share code, notes, and snippets.

@mlcollard
Created March 18, 2026 14:14
Show Gist options
  • Select an option

  • Save mlcollard/f418f1fd307b5ab03fd49b7d97561edc to your computer and use it in GitHub Desktop.

Select an option

Save mlcollard/f418f1fd307b5ab03fd49b7d97561edc to your computer and use it in GitHub Desktop.
Default lambda Capture Examples
[&, x, y]() { z = 10; return x + y + z; }
[&, y]() { x = 5; return x + y; }
[=]() mutable { x++; return x; }
[=, &x]() { x = 5; return x + y; }
[=, &x, &z]() { x += z; return x; }
[=, &x, z = x * 2]() mutable { x = z; return x; }
[=, &x]() mutable { ++x; ++y; return x + y; }
[&, y]() mutable { ++x; ++y; return x + y; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment