You can declare a class with the [[nodiscard]] attribute. It may be useful when you know from the semantics of this class that whenever it's returned from a function, it must be used for something. I have exactly this case, and it would be very convenient to tag the class with [[nodiscard]] instead of each individual function that returns it. However, there's one complication. This is the type that I need to make [[nodiscard]]:
using ConnectionStruct = std::pair<std::shared_ptr<CMutex>, std::shared_ptr<SignalFunction>>;
Is there a syntax to mark my ConnectionStruct as [[nodiscard]]?
[[nodiscard]] cannot be applied to aliases. Only to:
The attribute-token nodiscard may be applied to the declarator-id in a function declaration or to the declaration of a class or enumeration.
Emphasis added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With