Get array of elements the base type from Variant

RomulT romu777 at bk.ru
Wed Nov 20 22:31:51 PST 2013


On Thursday, 21 November 2013 at 05:44:53 UTC, evilrat wrote:
> On Thursday, 21 November 2013 at 05:16:10 UTC, RomulT wrote:
>> Hi, help please, how I get array of elements the base type 
>> from Variant?
>>
>>
>> http://dpaste.dzfl.pl/6dd70f9b
>
> may be there is a way to cast array directly but i doubt.
>
> so you need either to do this
>
> 	IXXX[] x = [new XXX(), new XXX()];
> 	Variant v = x;
> 	writeln(v.get!(IXXX[]));
>
> or cast all members of original array to its base type
>
> 	XXX[] x = [new XXX(), new XXX()];
> 	Variant v = x;
>
> 	foreach( ixx ; v.get!(XXX[]) )
> 	  writeln(cast(IXXX)ixx.get());
Yes, it a work, thank you. The problem occurs when, in Variant 
already recorded XXX[] and it is necessary to extract the IXXX[], 
because in the place used nothing is known about type XXX.


More information about the Digitalmars-d-learn mailing list