Best way to make a template function conditionally @trusted

tsbockman thomas.bockman at gmail.com
Thu Apr 1 22:35:01 UTC 2021


Suppose I have a templated struct member function for which I can 
compute at compile-time when the function is memory safe, and 
when it is not. But, the compiler cannot correctly determine this 
automatically.

What is the best way to express this in code? Other than 
straight-up duplicating the implementation, the only answer I've 
come up with so far is to create a `private @system` 
implementation function, and then separate `public @system` and 
`public @trusted` wrappers with appropriate template constraints.

Is there a better way?


More information about the Digitalmars-d-learn mailing list