@@ -25,11 +25,11 @@ Advanced Generic lambdas, utilizing mutable state, mapping
2525_ Why is this important?_
2626_ Why do we want to learn/teach this topic?_
2727
28- * function objects in relation to the standard library...
28+ * Function objects in relation to the standard library, e.g. for passing functions to the standard algorithms or auxiliary functions
2929* Allows the developer to define and pass functionality as values/data/information
3030* Allows developer to operate in a functional-programming mindset
31- * Improves code readdability by localizing the code
32- * Effective means to help refactoring code from long functions to re-usable functions
31+ * Improves code readability by localizing the code
32+ * Making code more compact by writing functions in-place
3333* Library designs taking callables allows the library to be customizable for the consumer, while lambdas make this usage approachable
3434
3535### Topic introduction
@@ -44,7 +44,7 @@ Lambdas were added in C++11 and have grown in power and functionality ever since
4444
4545A student:
4646_ TODO: Add cross-reference to these
47- Explain capture-by- value and capture-by- reference
47+ Explain function argument passing by value or by reference
4848
4949#### Student outcomes
5050
@@ -55,10 +55,11 @@ _Max 5 items._
5555A student should be able to:
5656
57571 . Use a lambda taking a concrete type as a parameter and return a value
58- 2 . transform a function definition into a lambda and use it
59- 3 . enumerate trade-offs of code-locality using lambdas vs code reuse with free-functions
60- 4 . assign a lambda to a variable for multiple calls
61- 5 . named lambdas to increase code readability
58+ 2 . Transform a function definition into a lambda and use it
59+ 3 . Enumerate trade-offs of code-locality using lambdas vs code reuse with free-functions
60+ 4 . Assign a lambda to a variable for multiple calls
61+ 5 . Named lambdas to increase code readability
62+ 6 . Explain capture-by-value and capture-by-reference
6263
6364
6465
@@ -83,9 +84,10 @@ A student should be able to:
8384
84851 . Utilize ` std::function ` as a means to hold and transfer lambdas
85862 . Define a function-template taking a lambda as a template parameter
86- 3 . specify, per parameter, whether to capture by reference or value
87- 4 . specify the default capture type for a lambda
88- 5 . use a lambda in a class, capturing and utilizing class data via ` this `
87+ 3 . Specify, per parameter, whether to capture by reference or value
88+ 4 . Specify the default capture type for a lambda
89+ 5 . Specify the return type for a lamda function, if not detected by the compiler
90+ 5 . Use a lambda in a class, capturing and utilizing class data via ` this `
8991
9092#### Caveats
9193
@@ -111,38 +113,40 @@ guidance where one can continue to investigate this topic in more depth._
111113A student should be able to:
112114
1131151 . Use a lambda to introduce a new identifier for use within the body of the lambda
114- 2 . explain the relationships between generic lambdas and templates
115- 3 . construct an object with choice between 2 identifiers , using immediately-dispathced lambda
116- 4 . utilize an immediately dispatched lambda to encode multiple statements where the language requires an expression
117- 5 . use the ` mutable ` keyword to allow changing a captured-by-value or lambda-local value within the lambda body
118- 6 . explicitly specify the return type for a lambda
119- 7 . explain under what conditions an explicit return type is necessary
120-
116+ 2 . Explain the relationships between generic lambdas and templates
117+ 3 . Construct an object with choice between 2 constructors , using immediately-dispatched lambda (see first listing)
118+ 4 . Utilize an immediately dispatched lambda to encode multiple statements where the language requires an expression
119+ 5 . Use the ` mutable ` keyword to allow changing a captured-by-value or lambda-local value within the lambda body
120+ 6 . Explicitly specify the return type for a lambda
121+ 7 . Explain under what conditions an explicit return type is necessary
122+
121123#### Caveats
122124
123125#### Points to cover
124126
125- Construct an object with choice between 2 identifiers :
127+ Construct an object with choice between 2 constructors :
126128```
127129class X;
128130bool b;
129131X x = [c = b](){ if (c) return X(5, 10) else X("a", "b"); }();
130132```
131133
132- multiple statements in a single expression
134+ Todo add caption
133135```
134136assert([](){
135137 std::vector v{1, 2, 3, 4, 5};
136138 for (auto x: v) std::cout << v << std::endl;
137139}());
138140```
139141
140- Capture can introduce new names
142+
143+ Capture can introduce new names by initializing them as ` capture-default `
141144```
142145char const* const s = "5";
143146[x=atoi(s)](){}
144147```
145148
149+ ` Capture-default ` variables can be altered by the lambda body if the lamda is marked as ` mutable `
146150```
147151std::ranges::for_each(
148152 std::vector{1,2,3,4,5},
0 commit comments