April 2020
Intermediate to advanced
412 pages
9h 58m
English
More information about the [[nodiscard]] attribute can be found on its reference page (https://en.cppreference.com/w/cpp/language/attributes/nodiscard). Starting from C++20, the nodiscard attribute can include a string literal, explaining why the value should not be discarded; for example, [[nodiscard("Check for write errors")]].
It is important to understand that compliance with safety guidelines does make your code safer, but does not guarantee it. In our implementation of TimeSaver2, we use the value returned by time, but we do not check whether it is valid. Instead, we write to the output file unconditionally. Similarly, if write returns a non-zero number, it can still write less data to the file than requested. Even if ...