www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Get array of elements the base type from Variant

reply "RomulT" <romu777 bk.ru> writes:
Hi, help please, how I get array of elements the base type from 
Variant?


http://dpaste.dzfl.pl/6dd70f9b
Nov 20 2013
parent reply "evilrat" <evilrat666 gmail.com> writes:
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());
Nov 20 2013
parent reply "RomulT" <romu777 bk.ru> writes:
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.
Nov 20 2013
parent reply "evilrat" <evilrat666 gmail.com> writes:
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.
Nov 20 2013
parent "RomulT" <romu777 bk.ru> writes:
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.
Nov 21 2013