Simplification of @trusted

vit vit at vit.vit
Thu Jun 17 04:24:28 UTC 2021


On Wednesday, 16 June 2021 at 11:38:54 UTC, RazvanN wrote:
> ...
>
> Cheers,
> RazvanN
>
> [1] https://issues.dlang.org/show_bug.cgi?id=17566
> [2] https://github.com/dlang/dlang.org/pull/2260


Yes
@trusted lamdas are ugly but necessary in templates where 
@safe/@system is deducted.

```d

struct Foo{
	
     int test()@safe{
     	return 1;
     }

}
struct Bar{
	
     int test()@system{
     	return 2;
     }

}

void system_fn()@system{

}

int template_fn(T)(T x){
     ()@trusted{
     	system_fn();
     }();

     return x.test();
}


void main()@safe{

	template_fn(Foo.init);   //ok
	template_fn(Bar.init);   //Error: `@safe` function `D main` 
cannot call `@system` function
}

```




More information about the Digitalmars-d mailing list