Checking function callability in D1 (aka static try-catch)

Christian Kamm kamm-incasoftware at
Sun Dec 7 02:08:59 PST 2008

> This topic came up (again) fairly recently, and a solution was
> proposed, but I found a case where that solution doesn't work.
> The objective is to do a static check to see if something is callable
> with particular argument types, and if so call it.
> The proposed solution was to use '.init' like so:
>     static if (is(typeof( some_function(ArgType.init) ))) {
>         // call some_function , or make an alias to it or whatever
>     }
> But this doesn't always work if some function takes a ref argument.

I didn't follow the original discussion, but what about:

template makeValue(T...) { T makeValue; }
template isCallable(alias s, ArgTy...) {
  const bool isCallable = is(typeof(s(makeValue!(ArgTy))));

More information about the Digitalmars-d mailing list