C++ Logo


Advanced search

Subject: Re: [std-proposals] nodiscard
From: Peter C++ (peter.cpp_at_[hidden])
Date: 2020-10-14 05:37:37


FWIW, I consider adding nodiscard to a typedef a potentially nice idea, but otoh it might be much better to replace the typedef with a strong type wrapper, where one can add the nodiscard.

Your question also gives me ideas To add nodiscard to my strong typing framework PSsst.

Conditional nodiscard I think is overkill.

sent from a mobile device so please excuse strange words due to autocorrection.
Peter Sommerlad
+41-79-432 23 32

> On 14 Oct 2020, at 10:12, Magnus Fromreide via Std-Proposals <std-proposals_at_[hidden]> wrote:
> 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
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups