Date: Sat, 31 May 2025 08:25:04 +0200
I believe this problem is something to be solved in the future using reflection. Hopefully, we will get some form of meta-classes eventually. The meta class could then mark all member functions noexcept.
As for checking if a type is noexcept, reflection will have a way to query user-defined attributes. Just mark these classes with the proper attribute.
However, coming back to you’re example: In many cases it is more useful to specify the minimum requirements (just two specific member functions being noexcept in your example) instead of requiring that all member functions are noexcept.
> On May 28, 2025, at 11:36 AM, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> There are times when I'm writing template code and I end up with
> 'noexcept' specifications something like:
>
> template<typename T>
> void Func(T&&) noexcept( noexcept( std::declval<T&>.clear() ) &&
> noexcept(std::declval<T&>.some_other_method() ) );
>
> when what I really want is that 'T' would be some sort of class whose
> methods never throw.
>
> Would it be helpful at all to be able to mark a class or an individual
> object as 'noexcept'? Maybe something like:
>
> class noexcept MyClass { . . . };
>
> or maybe even mark an object:
>
> MyClass noexcept my_object;
>
> so that we get a compiler error if any of the class's methods are not
> marked as 'noexcept'?
>
> (I think marking the class would be a lot less work, as marking an
> object I think would mean adding a cv-qualifier to the language)
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
As for checking if a type is noexcept, reflection will have a way to query user-defined attributes. Just mark these classes with the proper attribute.
However, coming back to you’re example: In many cases it is more useful to specify the minimum requirements (just two specific member functions being noexcept in your example) instead of requiring that all member functions are noexcept.
> On May 28, 2025, at 11:36 AM, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> There are times when I'm writing template code and I end up with
> 'noexcept' specifications something like:
>
> template<typename T>
> void Func(T&&) noexcept( noexcept( std::declval<T&>.clear() ) &&
> noexcept(std::declval<T&>.some_other_method() ) );
>
> when what I really want is that 'T' would be some sort of class whose
> methods never throw.
>
> Would it be helpful at all to be able to mark a class or an individual
> object as 'noexcept'? Maybe something like:
>
> class noexcept MyClass { . . . };
>
> or maybe even mark an object:
>
> MyClass noexcept my_object;
>
> so that we get a compiler error if any of the class's methods are not
> marked as 'noexcept'?
>
> (I think marking the class would be a lot less work, as marking an
> object I think would mean adding a cv-qualifier to the language)
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-05-31 06:25:21