Daily bit(e) of C++ | [[nodiscard]] constructors and types
Daily bit(e) of C++ #176, Non-typical use cases for [[nodiscard]]: marking constructors and types as [[nodiscard]].
The typical use case for [[nodiscard]] is for marking functions whose returns should not be ignored. However, we can also apply [[nodiscard]] to constructors and entire types.
When applied to a constructor, the constructor cannot be used to construct ephemeral temporaries, i.e., temporaries that are immediately destroyed.
When applied to a type, results of that type will be considered [[nodiscard]] even when not marked as such by the function.