Title: Theory / Unimportant / CS / Programming / C++ / Effective modern / 06 Lambda

Name: A closure
Definition: A function object created by lambda
Page: 5, 215
Chapter: intro, 6
Context: C++

Name: A lambda
Definition: A lambda expression
Page: 5
Chapter: intro
Context: c++
Definition2: A closure returned by a lambda expression
Conjdef: Depending on the context, either

Instruction: [args](params) {body}
Page: 215
Language: C++
Chapter: 6
Returns: A function which takes params, return body; captures the args from the context
Name: A lambda expression

Name: A  closure class
Definition: A class from which a closure is instantiated
Page: 216
Chapter: 6
Context: C++

Question: What is the default capture
Answer: By reference
Page: 216
Chapter: 6
Section: 31
Context: lambda in C++

Instruction: [&, local_arg_1, ..., local_arg_n](args){body}
Page: 216, 294
Language: C++
Chapter: 6 modern, 11manual
Section: 31, 11
Returns: Same as [local_arg_1, ..., local_arg_n](args){body}, capturing everything which are not explicitly listed by reference
Assuming: The lambda lifespan is included in the captured value lifespan.

Instruction: &foo
Page: 216
Effect: capture foo by reference
Language: C++
Context: lambda capture
Chapter: 6
Section: 31

Question: When is it okay to capture with [&]
Answer: only if it is clear that the lambda never leave current context, so no dangling reference
Page: 216
Chapter: 6
Section: 31
Context: lambda capture

Instruction: [=, local_arg_1, ..., local_arg_n](args){body}
Page: 216, 294
Language: c++
Context: lambda capture
Chapter: 6 modern, 11manual
Section: 31, 11
Returns: Same as [local_arg_1, ..., local_arg_n](args){body}, capturing by-value local non-static variable not explicitly listed
Intuition: lambda avoiding dangling reference

Question: What occurs if you use automatic capture and the lambda body access a member of the class
Answer: the lambda capture `this`
Page: 222
Chapter: 6
Section: 31

Instruction: foo = bar
Page: 222
Effect: in the capture, create a constant foo, initialized with the current value of bar
Language: c++
Context: lambda capture
Chapter: 6
Section: 31

Question: What are the risk with default by-value capture
Answer: you only capture local non-static variable. You may risk to try to capture constant, static value, member; so their values are not fixed
Page: 222
Chapter: 6
Section: 31
Context: C++