Summary
This episode explores how to apply the [[nodiscard]] attribute to constructors in C++20, which warns when constructor results are ignored. Jason demonstrates how this differs from applying [[nodiscard]] to an entire type and shows examples using unique_lock and unique_ptr. This feature is particularly useful for constructors that acquire resources, ensuring that users don't accidentally discard objects that have acquired a resource, preventing potential resource leaks.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[thread.lock.unique]40% match -
[thread.mutex.class]40% match