Thread overview |
---|
November 21, 2013 Get array of elements the base type from Variant | ||||
---|---|---|---|---|
| ||||
Hi, help please, how I get array of elements the base type from Variant? http://dpaste.dzfl.pl/6dd70f9b |
November 21, 2013 Re: Get array of elements the base type from Variant | ||||
---|---|---|---|---|
| ||||
Posted in reply to RomulT | 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 Re: Get array of elements the base type from Variant | ||||
---|---|---|---|---|
| ||||
Posted in reply to evilrat | 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 Re: Get array of elements the base type from Variant | ||||
---|---|---|---|---|
| ||||
Posted in reply to RomulT | 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 Re: Get array of elements the base type from Variant | ||||
---|---|---|---|---|
| ||||
Posted in reply to evilrat | 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. |
Copyright © 1999-2021 by the D Language Foundation