Skip to content

Commit 22e29ab

Browse files
committed
Strawman for lambdas
Issue #35
1 parent d6bf815 commit 22e29ab

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

sources/modules/functions/lambdas.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
## Module name: Lambdas
2+
3+
_Skeleton descriptions are typeset in italic text,_
4+
_so please don't remove these descriptions when editing the topic._
5+
6+
### Overview
7+
8+
_Provides a short natural language abstract of the module’s contents._
9+
_Specifies the different levels of teaching._
10+
11+
------------------------------------------------------------------------
12+
Level Objective
13+
----------------- ------------------------------------------------------
14+
Foundational Define and execute lambdas with basic capture syntax
15+
16+
Main Passing instances of lambdas for use in external code
17+
18+
Advanced Generic lambdas, utilizing mutable state, mapping
19+
to function objects, decay to function pointers
20+
21+
------------------------------------------------------------------------
22+
23+
### Motivation
24+
25+
_Why is this important?_
26+
_Why do we want to learn/teach this topic?_
27+
28+
* function objects in relation to the standard library...
29+
* Allows the developer to define and pass functionality as values/data/information
30+
* 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
33+
* Library designs taking callables allows the library to be customizable for the consumer, while lambdas make this usage approachable
34+
35+
### Topic introduction
36+
37+
_Very brief introduction to the topic._
38+
39+
Lambdas were added in C++11 and have grown in power and functionality ever since.
40+
41+
### Foundational: Define and execute lambdas with basic capture syntax
42+
43+
#### Background/Required Knowledge
44+
45+
A student:
46+
_TODO: Add cross-reference to these
47+
Explain capture-by-value and capture-by-reference
48+
49+
#### Student outcomes
50+
51+
_A list of things "a student should be able to" after the curriculum._
52+
_The next word should be an action word and testable in an exam._
53+
_Max 5 items._
54+
55+
A student should be able to:
56+
57+
1. Use a lambda taking a concrete type as a parameter and return a value in response
58+
2.
59+
3.
60+
4.
61+
5.
62+
63+
#### Caveats
64+
65+
_This section mentions subtle points to understand, like anything resulting in
66+
implementation-defined, unspecified, or undefined behavior._
67+
68+
#### Points to cover
69+
70+
_This section lists important details for each point._
71+
72+
### Main: Passing instances of lambdas for use in external code
73+
74+
#### Background/Required Knowledge
75+
76+
* All of the above.
77+
78+
#### Student outcomes
79+
80+
A student should be able to:
81+
82+
1. Utilize std::function as a means to hold and transfer lambdas
83+
2. Define a function-template taking a lambda as a template parameter
84+
3. Use captures to change
85+
86+
#### Caveats
87+
88+
#### Points to cover
89+
90+
Capture can introduce new names
91+
```
92+
char const* const s = "5";
93+
[x=atoi(s)](){}
94+
```
95+
96+
```
97+
std::ranges::for_each(
98+
std::vector{1,2,3,4,5},
99+
[init = true] (auto&& x) mutable {
100+
if (init)
101+
{ std::cout << x; init = false};
102+
else
103+
{ std::cout << ',' << x;}
104+
});
105+
```
106+
107+
### Advanced
108+
Explain why they can't write out the type of a lambda?
109+
_These are important topics that are not expected to be covered but provide
110+
guidance where one can continue to investigate this topic in more depth._

0 commit comments

Comments
 (0)