0Pricing
C++ Academy · Lesson

Lambda Expressions Capture Mutable Generic

Write lambdas with captures, mutable semantics, and generic auto parameters.

What is a Lambda?

A lambda is an inline anonymous function object. Use it where you would otherwise write a tiny named function or a struct with operator().

auto square = [](int x) { return x * x; };
std::cout << square(5);   // 25

Syntax Anatomy

A lambda has four parts:

  • [capture] — what variables from the surrounding scope to use
  • (parameters) — like a function parameter list
  • -> return_type — optional, often deduced
  • { body }

All lessons in this course

  1. auto decltype and Type Deduction
  2. Range-based for nullptr and enum class
  3. Lambda Expressions Capture Mutable Generic
  4. Structured Bindings and if-init C++17
← Back to C++ Academy