Skip to content

Commit 995c556

Browse files
hageboecksponce
andcommitted
Add notes to cheat sheet.
Co-authored-by: Sebastien Ponce <[email protected]>
1 parent 167c554 commit 995c556

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

code/ExerciseSchedule_AdvancedCourse.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ As a prerequisite for variadic templates, and in case it was not covered in day
4949

5050
### variadic templates ([cheatSheet](ExercisesCheatSheet.md#variadic-templates-directory-variadic))
5151

52-
### Spaceship operator <=> ([cheatSheet](ExercisesCheatSheet.md#spaceship-operator-directory-spaceship))
52+
### Spaceship operator <=> ([cheatSheet](ExercisesCheatSheet.md#spaceship-operator-))
5353

5454
### Concepts ([cheatSheet](ExercisesCheatSheet.md#concepts-directory-concepts))

code/ExercisesCheatSheet.md

+20
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ Here we have four code snippets that will benefit from using smart pointers.
140140
- `problem3` is an example of shared ownership where `std::shared_pointer` should be used.
141141
- `problem4` demonstrates the usage of `shared_ptr` as class members. It has a second part where a `weak_ptr` can be used, but can be skipped if not enough time.
142142
143+
### std::optional (directory: `optional`)
144+
Use std::optional to signify disallowed values in a computation.
145+
1. Use std::optional as return value of the mysqrt function. Use `nullopt_t` for negative arguments. Note that `return {}` will create a `nullopt_t` automatically.
146+
2. Given that the return type changes, modify the square function accordingly to take into account cases where a `nullopt_t` is given as input. Note that `std::optional` can be directly used in an if statement as if it would be a boolean to check whether is value is present
147+
148+
### std::variant (directory: `variant`)
149+
Use the variant as an alternative to inheritance. The goal is to understand
150+
1. That the base class is unnecessary when variant is used
151+
2. That no dynamic allocations and polymorphism are necessary because the variant can directly be pushed into the vector
152+
3. That there's multiple ways to "visit" the vector.
153+
- Either with explicit checking of the type (solution 1)
154+
- Or automatic visitation with std::visit (solution 2). Note that generic lambdas make the std::visit solution extremely short.
155+
143156
144157
Expert Exercises
145158
----------------
@@ -170,6 +183,13 @@ Solutions:
170183
To intersperse the ", " between elements, you need more logic so a fold over << won't work. Use a fold over comma.
171184
Finally, to omit the last ", ", just use a conditional expression comparing the expanded index pack against the index pack size
172185
186+
187+
### Spaceship operator <=>
188+
The goal is to write a custom <=>, and to understand that when ordering according to the norm of a complex, a `partial_ordering` is required.
189+
Many numbers can have the same norm, but a different phase.
190+
Given that an implementation for <=> is provided, an implementation for == is required as well. It's OK to default it. It is not possible to
191+
derive it from equivalence (<=> evaluates to 0).
192+
173193
### Concepts (directory: `concepts`)
174194
175195
To be filled

0 commit comments

Comments
 (0)