On 2010-12-19 15:30:50 -0500, Ary Borenszweig <a...@esperanto.org.ar> 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
michel.for...@michelf.com
http://michelf.com/

Reply via email to