liveBook · Manning

Regex grouping

As explained in Modern C, Third Edition

A capture is a lambda specification identifying variables from the surrounding scope that are made available inside the lambda.

A lambda’s capture list, written in `[ ... ]`, is the only part that can read the surrounding context. An init-capture uses `identifier = initializer`; its semantics resemble `auto` type inference with `const` qualification. Captures that allow writing are mentioned but not developed. section 18.4

Captures in SWAP

A `SWAP` macro uses captures such as `swap_p1 = &(X)` and `swap_p2 = &(Y)` to make the operands available inside the lambda, much like function parameters. section 18.4

How Modern C, Third Edition covers it

How deep it goes
Defines init-capture syntax and its inferred, const-qualified semantics, but leaves writable captures beyond scope.
Examples
Uses pointer init-captures in a `SWAP` macro to bring its operands into a lambda.
What you can do after
Understand how init-captures make surrounding expressions available inside a lambda.
How it connects
Connects lambda captures with macros, function parameters, and type inference.

Also explained in

Compare how 6 books explain regex grouping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.