|
64 | 64 | "A first version of `select` is provided, which looks as follows:\n",
|
65 | 65 | "\n",
|
66 | 66 | "```c++\n",
|
67 |
| - "template<class UnaryPredicate> |
| 67 | + "template<class UnaryPredicate>\n", |
68 | 68 | "std::vector<int> select(const std::vector<int>& v, UnaryPredicate pred)\n",
|
69 | 69 | "{\n",
|
70 |
| - " // TODO Instead of the line below, create a vector w and use a "copy_if" algorithm\n", |
| 70 | + " // TODO Instead of the line below, create a vector w and use a \"copy_if\" algorithm\n", |
71 | 71 | " // call to copy all elements from v to w that are selected by the unary predicate.\n",
|
72 | 72 | " auto w = v;\n",
|
73 | 73 | " return w;\n",
|
74 | 74 | "}\n",
|
75 | 75 | "```\n",
|
76 | 76 | "\n",
|
77 |
| - "[exercise0.cpp]: ./exercise0.cpp" |
| 77 | + "[exercise0.cpp]: ./exercise0.cpp\n", |
78 | 78 | "\n",
|
79 | 79 | "The example compiles and runs as provided, but it produces incorrect results due to the erroneous `select` implementation.\n",
|
80 | 80 | "Replace the erroneous line by an appropriate call to the `copy_if` algorithm.\n",
|
81 | 81 | "Hint: You can't allocate the right number of elements for `w` in advance, because you don't know how many elements the `copy_if` algorithm is going to copy. Instead, use `std::back_inserter` to create an iterator which inserts elements at the back of `w` and resizes the vector appropriately as the algorithm progresses.\n",
|
82 |
| - "Once you fix the code, the following block should compile and run correctly:\n" |
83 |
| - "\n", |
| 82 | + "Once you fix the code, the following block should compile and run correctly:\n", |
| 83 | + "\n" |
84 | 84 | ]
|
85 | 85 | },
|
86 | 86 | {
|
|
188 | 188 | "\n",
|
189 | 189 | "Once the code is completed, the following blocks should complete properly and produce the same output as in exercise 0.\n",
|
190 | 190 | "\n",
|
191 |
| - "[exercise1.cpp]: ./exercise1.cpp" |
192 |
| - "\n", |
| 191 | + "[exercise1.cpp]: ./exercise1.cpp\n", |
| 192 | + "\n" |
193 | 193 | ]
|
194 | 194 | },
|
195 | 195 | {
|
|
294 | 294 | "\n",
|
295 | 295 | "Once the code is completed, the following blocks should complete properly and produce the same output as in exercise 0 and exercise 1.\n",
|
296 | 296 | "\n",
|
297 |
| - "[exercise2.cpp]: ./exercise2.cpp" |
298 |
| - "\n", |
| 297 | + "[exercise2.cpp]: ./exercise2.cpp\n", |
| 298 | + "\n" |
299 | 299 | ]
|
300 | 300 | },
|
301 | 301 | {
|
|
388 | 388 | "!dpcpp -std=c++20 -Ofast -DNDEBUG -isystem/usr/local/range-v3/include -o select solutions/exercise2.cpp\n",
|
389 | 389 | "!./select 30"
|
390 | 390 | ]
|
391 |
| - }, |
| 391 | + } |
392 | 392 | ],
|
393 | 393 | "metadata": {
|
394 | 394 | "kernelspec": {
|
|
0 commit comments