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
The following example code in exercise 13-5 refers to the wrong thing:
long fib_sum(size_t n) {
// TODO: Adapt code from Exercise 12.1
return 0;
}
Here is the actual contents of Exercise 12.1:
12-1. Reimplement the narrow_cast in Listing 6-6 to return a std::optional. If the cast would result in a narrowing conversion, return an empty optional rather than throwing an exception. Write a unit test that ensures your solution works.
Perhaps you instead intended to refer to the recursive version of the Fibonacci algorithm, considering that its naive implementation performance is terrible and easily noticed. Or perhaps you are only intending for the summing of the Fibonacci sequence itself to be the source of the performance overhead. The clarity here could be improved.
...
Also, why are you passing by const reference in the following example code, from that same example code block?:
long cached_fib_sum(const size_t& n) {
static std:: map <long, long> cache;
//TODO: Implement me
return 0;
}
There doesn't seem to be a point to doing that, although it doesn't really harm anything either in this case.
The text was updated successfully, but these errors were encountered:
On further thought, I estimate that you were not referring to the recursive version of the Fibonacci sum, considering that the iterative version is already plenty slow when you sum it together as in this exercise.
The following example code in exercise 13-5 refers to the wrong thing:
Here is the actual contents of Exercise 12.1:
Perhaps you instead intended to refer to the recursive version of the Fibonacci algorithm, considering that its naive implementation performance is terrible and easily noticed. Or perhaps you are only intending for the summing of the Fibonacci sequence itself to be the source of the performance overhead. The clarity here could be improved.
...
Also, why are you passing by const reference in the following example code, from that same example code block?:
There doesn't seem to be a point to doing that, although it doesn't really harm anything either in this case.
The text was updated successfully, but these errors were encountered: