There's an isDelegate template function in std.traits, but I think there's some kind of bug there. I've reported it and I'm waiting for answers.
Otherwise there are other functions you can use, e.g.: isSomeFunction(T), isCallable(T), is(FunctionTypeOf(T) == delegate).. On 12/19/10, Michel Fortin <[email protected]> wrote: > On 2010-12-19 15:30:50 -0500, Ary Borenszweig <[email protected]> said: > >> But that is a template: >> >> int foobar2(int delegate(int x) f)() { >> } >> >> It's a template that doesn't work because I have to write it in a >> different way. Sorry, I tried many different template constraints and >> none of them work. >> >> I tried these: >> >> int foobar2(alias f)() >> if (typeof(f) == typeid(int delegate(int x))) >> if (is(typeof(f) == int delegate(int))) >> if (is(typeof(f) == delegate)) >> >> What do I have to write to make it work? > > int foobar2(alias f)() > if (is(typeof(f(int.init)) == int)) > > On the plus side, it'll not only work with delegates but also with > regular functions, template functions, and objects with an opCall > member. > > If you absolutely want to limit it to a delegate, you can try this: > > int foobar2(alias f)() > if (is(typeof(&f) == int delegate(int))) > > -- > Michel Fortin > [email protected] > http://michelf.com/ > >
