Daily bit(e) of C++ | [[nodiscard]] attribute
Daily bit(e) of C++ #113, The C++17 [[nodiscard]] attribute.
C++17 introduced the [[nodiscard]]
attribute that triggers a compiler warning when the result of a function call is discarded.
At a minimum, this attribute should be used for functions that are expensive to run and query functions that might be confused with their action counterparts.
Useful for return but I also like to sometimes use it on arguments, e.g. having an argument that is used in release build but not in debug build, or when are implementing an interface and an argument is not really needed in that context. void foo(int n, [[nodiscard]] int m) -- if the compiler switch is on for treating such as an error.