Thread overview
Get array of elements the base type from Variant
Nov 21, 2013
RomulT
Nov 21, 2013
evilrat
Nov 21, 2013
RomulT
Nov 21, 2013
evilrat
Nov 21, 2013
RomulT
November 21, 2013
Hi, help please, how I get array of elements the base type from Variant?


http://dpaste.dzfl.pl/6dd70f9b
November 21, 2013
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());
November 21, 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.
November 21, 2013
On Thursday, 21 November 2013 at 06:31:54 UTC, RomulT wrote:
> 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.

so you need just to cast XXX[] to IXXX[] ? AFAIK arrays can't be casted to other types. but you can use std.conv.to to convert it.

writeln( std.conv.to!(IXXX[])(v.get!(XXX[])) );

but if you put another class derived from IXXX you can see they are still initial types, not IXXX as you may expect.
November 21, 2013
On Thursday, 21 November 2013 at 07:00:43 UTC, evilrat wrote:
> On Thursday, 21 November 2013 at 06:31:54 UTC, RomulT wrote:
>> 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.
>
> so you need just to cast XXX[] to IXXX[] ? AFAIK arrays can't be casted to other types. but you can use std.conv.to to convert it.
>
> writeln( std.conv.to!(IXXX[])(v.get!(XXX[])) );
>
> but if you put another class derived from IXXX you can see they are still initial types, not IXXX as you may expect.

I rather had in view that's - http://dpaste.dzfl.pl/43290b8c, probably Variant has the limited realization.