Re: Store any callable in an array

2018-05-07 Thread wjoe via Digitalmars-d-learn
On Monday, 7 May 2018 at 10:20:22 UTC, ag0aep6g wrote: On 05/07/2018 04:41 AM, wjoe wrote: Could you elaborate on the unsafe destructor please? If TFunc has an unsafe destructor, asDelegate is also not safe and can't be @trusted. An example of how that can break safety: auto

Re: Store any callable in an array

2018-05-07 Thread ag0aep6g via Digitalmars-d-learn
On 05/07/2018 04:41 AM, wjoe wrote: Could you elaborate on the unsafe destructor please? If TFunc has an unsafe destructor, asDelegate is also not safe and can't be @trusted. An example of how that can break safety: auto asDelegate(TFunc)(TFunc func) @trusted { import

Re: Store any callable in an array

2018-05-06 Thread wjoe via Digitalmars-d-learn
Thanks for replying. On Friday, 4 May 2018 at 19:12:16 UTC, ag0aep6g wrote: On 05/04/2018 06:33 PM, Neia Neutuladh wrote: auto asDelegate(TFunc)(TFunc func) @trusted {     import std.functional : toDelegate;     return toDelegate(func); } The "@trusted" means that you promise this thing is

Re: Store any callable in an array

2018-05-06 Thread wjoe via Digitalmars-d-learn
Thanks for replying. On Saturday, 5 May 2018 at 00:30:35 UTC, Neia Neutuladh wrote: On Friday, 4 May 2018 at 19:12:16 UTC, ag0aep6g wrote: [...] 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. Actually it's

Re: Store any callable in an array

2018-05-05 Thread ag0aep6g via Digitalmars-d-learn
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.

Re: Store any callable in an array

2018-05-04 Thread Neia Neutuladh via Digitalmars-d-learn
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? If it were @safe, the compiler would accept it. Looking at the code, I believe there are several casts that the compiler can't verify but are used safely.

Re: Store any callable in an array

2018-05-04 Thread ag0aep6g via Digitalmars-d-learn
On 05/04/2018 06:33 PM, Neia Neutuladh wrote: auto asDelegate(TFunc)(TFunc func) @trusted {     import std.functional : toDelegate;     return toDelegate(func); } The "@trusted" means that you promise this thing is safe, even if the compiler can't be certain. If toDelegate isn't (always)

Re: Store any callable in an array

2018-05-04 Thread Neia Neutuladh via Digitalmars-d-learn
On Friday, 4 May 2018 at 15:36:29 UTC, wjoe wrote: I have a class that I want to be able to register callbacks and I'd like to be able to register any callable - functions, delegates, lambdas, anything. Is there another way to do it besides converting those toDelegate, which states a bug