Testing derived type

Koroskin Denis 2korden at gmail.com
Sat Jul 5 14:14:23 PDT 2008


On Sun, 06 Jul 2008 01:11:52 +0400, Koroskin Denis <2korden at gmail.com>  
wrote:

> On Sun, 06 Jul 2008 01:03:33 +0400, Nick Sabalausky <a at a.a> wrote:
>
>> I assume there's some way to do the following (D1 and Tango) without
>> converting to and comparing strings, but...how?
>>
>> module modA;
>> class base {}
>> class derivedA : base {}
>> class derivedB : base {}
>> class derivedC : base {}
>>
>> module modB;
>> base[] array;
>> foreach(base elem; array)
>> {
>>     if(elem.toString[locatePrior(elem.toString, '.')+1..$] !=
>> derivedA.stringof)
>>     { /* do stuff */ }
>> }
>>
>>
>
> Maybe this?
>
> ...
> if ( (cast(derivedA)elem) is null ) {
> 	/* do stuff */
> }
> ...

Or use

...
if ( elem.classinfo !is derivedA.classinfo ) {
	// do stuff
}
...

to skip derivedA instances only (and not derivatives).


More information about the Digitalmars-d-learn mailing list