From Jason Turner
Watch on YouTube

Summary

In this episode, Jason Turner explores the [[nodiscard]] attribute introduced in C++17 and enhanced in C++20. He demonstrates how it can help prevent bugs by forcing developers to handle return values that shouldn't be ignored. Using the example of a vector's empty() method, he shows how ignoring its return value is a common mistake (users often confuse it with clear()). C++20 extends the attribute to allow custom messages, making warnings more informative, and [[nodiscard]] can be applied to both functions and entire types.

Resources

Tags