Conditional nothrow/safe/nogc/etc?

Matt Elkins via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 29 22:07:25 PST 2016


On Saturday, 30 January 2016 at 05:57:34 UTC, H. S. Teoh wrote:
> A common idiom that we use is to write an attributed unittest 
> to verify that the function itself is @safe/etc.. This way, if 
> instantiated with safe/etc. types, the template will also be 
> safe/etc., but if instantiated with an unsafe type, it will 
> correspondingly be unsafe (instead of failing to compile if you 
> wrote @safe on the template). The unittest ensures that you do 
> not accidentally introduce un- at safe code into the template and 
> cause *all* instantiations to become un- at safe.
>
> 	auto mySafeCode(T)(T t) { ... }
>
> 	@safe unittest
> 	{
> 		auto x = mySafeCode(safeValue);
> 	}
>
>
> T

Seems sound. Thanks!



More information about the Digitalmars-d-learn mailing list