You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: code/ExercisesCheatSheet_All.md
+12-21Lines changed: 12 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -194,33 +194,24 @@ It can then be tried with e.g. reverse ordering of strings or an order of Comple
194
194
195
195
Level 3 : use the genericity of the Complex class and play with Complex of integers or Complex of Complex
196
196
197
-
### Standard algorithms (directory: `stl`)
197
+
### Smart pointers (directory: `smartPointers`)
198
+
199
+
Here we have four code snippets that will benefit from using smart pointers.
200
+
201
+
- `problem1` is a simple case of usage of `make_unique` with an observer pattern where the raw pointer should be used.
202
+
- `problem2` is an example of a collection of pointers. Move semantic has to be used to transfer ownership of newly created objects to the container (alternatively, `emplace_back`).
203
+
- `problem3` is an example of shared ownership where `std::shared_pointer` should be used.
204
+
- `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.
205
+
206
+
### Standard algorithms and lambdas (directory: `stl`)
198
207
199
208
The goal is to use STL algorithms. I would advise to start in this order :
200
209
201
210
- random_shuffle
202
211
- adjacent_difference
203
212
- first accumulate (the one for sums)
204
-
- second accumulate (sum of squares) with usage of "sumsquare<T>()" as BinaryOperation
205
-
- generate
206
-
207
-
One may want to only do the first 3 and go to next exercise to directly use lambdas for step 4 and 5;
208
-
209
-
### Lambda functions (directory: `lambdas`)
210
-
211
-
Can be merged into previous exercise as the easy (and modern) solution to step 4 and 5 where functors were needed in the STL exercises.
212
-
213
-
The accumulate lambda is a simple one, the one for generate involves a state to be captured by reference.
214
-
215
-
### Smart pointers (directory: `smartPointers`)
216
-
217
-
Here we have four code snippets that will benefit from using smart pointers.
218
-
219
-
- `problem1` is a simple case of usage of `make_unique` with an observer pattern where the raw pointer should be used.
220
-
- `problem2` is an example of a collection of pointers. Move semantic has to be used to transfer ownership of newly created objects to the container (alternatively, `emplace_back`).
221
-
- `problem3` is an example of shared ownership where `std::shared_pointer` should be used.
222
-
- `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.
223
-
213
+
- second accumulate (using lambda to compute sum of squares)
214
+
- generate (involves a state to be captured by reference)
0 commit comments