Store any callable in an array

ag0aep6g anonymous at
Sat May 5 10:26:38 UTC 2018

On 05/05/2018 02:30 AM, Neia Neutuladh wrote:
> On Friday, 4 May 2018 at 19:12:16 UTC, ag0aep6g wrote:
>> If toDelegate isn't (always) @safe, how can you be sure that your 
>> wrapper is?
> Looking at the code, I believe there are several casts that the compiler 
> can't verify but are used safely.

If you're right and the casts are used safely, and if that's the one 
thing that makes toDelegate @system, then toDelegate should be marked as 
@trusted. Or the casts should be @trusted, if they can be isolated like 

But belief isn't strong enough for that. You should be certain when 
applying @trusted. And thinking of all the ways that code might be 
unsafe is tricky, especially when you're dealing with arbitrary types in 
a template.

>> Also, TFunc may have an unsafe destructor.
[...]> If it's a user-defined type with
> opCall, that's something to pay attention to, but it's beyond the scope 
> of the original question.

That's the one. The scope of the original question doesn't matter if you 
don't restrain your function in the same way. Your function accepts 
structs, so you have to take them into account. Also, the thread is 
about "anything" callable. That includes structs with opCall.

More information about the Digitalmars-d-learn mailing list