Concepts? Template specialization depending on class functions?
Ben Phillips
Ben_member at pathlink.com
Thu Mar 2 18:51:31 PST 2006
In article <du7sda$2kmq$1 at digitaldaemon.com>, Oskar Linde says...
>
>Ben Phillips wrote:
>
>> In article <du751p$1imp$1 at digitaldaemon.com>, Ben Phillips says...
>>>
>>>Is it possible to determine whether a given class contains a specific
>>>member function?
>>>
>>
>> From reading the docs it seems like I should be able to do this using
>> "is", but the appropriate syntax is unclear and I can't seem to figure it
>> out. Does "is" make it possible to test of a class has a certain member
>> function and, if so, what is the correct syntax?
>
>I'm not fully sure of the syntax, but this seems to work:
>
>To test if a class T contains a method test:
>
>is(typeof(T.test) == function)
>
>Or conceptualized:
>
>template Testable(T) {
> const Testable = is(typeof(T.test) == function));
>}
>
>One could wish that you could write something like:
>
>is(typeof(T.test) == int function(T))
>
>To make sure that the function signature is OK, but this does not seem to
>work.
>
>Instead, the following works kind of but doesn't check the exact type of the
>arguments. To check if T contains a method with the signature similar to
>int test(int,int,int):
>
>is(typeof((new T).test(1,1,1)) == int)
>
>But will be true for e.g. a int test(real,real,real) too...
>
>/Oskar
Ah.. thanks! This helps a lot. You pointed out that your last method for testing
method signature and
arguments can be slightly ambiguous, but I doubt this will pose a problem in
most real world scenarios.
More information about the Digitalmars-d
mailing list