February 21, 2007 Re: Checking if a function exists | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Samukha | Max Samukha wrote: >> For all types you can use T.init as the dummy value to the function (I just remembered its existence). > > This works for module scope functions: > > static if (is(typeof(&.toString) == char[] function(T))) // '.' is the > module scope operator or use fully qualified name. Trickier ways might > exist. That doesn't work if there are multiple overloads of the same function, like with toString. I just tested it. Tyler's method worked, though. Thanks! -- Michiel |
February 21, 2007 Re: Checking if a function exists | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tyler Knott | Tyler Knott wrote:
> For all types you can use T.init as the dummy value to the function (I just remembered its existence).
Doesn't work for static arrays IIRC, since typeof(T[N].init) == T (for constant integer N)...
|
February 22, 2007 Re: Checking if a function exists | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michiel | On Wed, 21 Feb 2007 23:08:16 +0100, Michiel <nomail@please.com> wrote:
>Max Samukha wrote:
>
>>> For all types you can use T.init as the dummy value to the function (I just remembered its existence).
>>
>> This works for module scope functions:
>>
>> static if (is(typeof(&.toString) == char[] function(T))) // '.' is the
>> module scope operator or use fully qualified name. Trickier ways might
>> exist.
>
>That doesn't work if there are multiple overloads of the same function, like with toString. I just tested it.
>
>Tyler's method worked, though.
>
>Thanks!
Yes, my mistake
|
Copyright © 1999-2021 by the D Language Foundation