Conditional nothrow/safe/nogc/etc?

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 29 21:25:49 PST 2016


On 30/01/16 6:17 PM, Matt Elkins wrote:
> Is there any way to specify that a generic function is conditionally
> nothrow (or other function decorators), based on whether the template
> instantiation is nothrow? I'm looking for something akin to C++'s
> noexcept(noexcept(<expr>)), e.g.:
>
> template <class T> void foo() noexcept(noexcept(T())) {}
>
> I don't see anything about it on the functions grammar page
> (https://dlang.org/spec/function.html). I do see something to do with
> nothrow_ on the std.traits page, but I'm not sure how to use it to
> achieve this or whether that is the right approach.
>
> My actual use case is a non-generic method opAssign inside of a generic
> struct.

templated functions have attribute inference. Meaning if it can be 
nothrow it will be.
Regarding your real use case, again struct if templated so it should be 
inferred.


More information about the Digitalmars-d-learn mailing list