C++ Logo

std-proposals

Advanced search

nodiscard

From: Magnus Fromreide <magfr_at_[hidden]>
Date: Wed, 14 Oct 2020 10:12:03 +0200
Hi!

I have some ideas about the nodiscard attribute and would like to know if
they are reasonable.

First, I could see a use for binding of the nodiscard attribute to a typedef-
name like this:

typedef [[nodiscard]] int status;

or

using status = [[nodiscard]] int;

This would make any use of the type status have the nodiscard attribute just
like struct [[nodiscard]] ClassName does for a class.

The use for this feature is in old code following the old C conventions of
returning ints, but still allowing the reaaping of the benefits of
class-level nodiscard.


Second, would it be useful to have a conditional nodiscard like

template <class Result, class Error>
struct [[nodiscard(nodiscard(Result) || nodiscard(Error))]] expected
{ ... };

/MF

Received on 2020-10-14 03:12:10