Optimizing delegates

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Dec 19 14:54:27 PST 2010


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 <michel.fortin at michelf.com> wrote:
> On 2010-12-19 15:30:50 -0500, Ary Borenszweig <ary at 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.fortin at michelf.com
> http://michelf.com/
>
>


More information about the Digitalmars-d mailing list