Store any callable in an array
    Neia Neutuladh 
    neia at ikeran.org
       
    Fri May  4 16:33:24 UTC 2018
    
    
  
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 with @safe functions?
>
> Or better store each type in their own array ?
>
> Cheers!
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.
    
    
More information about the Digitalmars-d-learn
mailing list