Nesting Variants

evilrat evilrat666 at gmail.com
Tue May 21 21:41:34 PDT 2013


On Wednesday, 22 May 2013 at 01:04:35 UTC, Wyatt wrote:
>
> I was trying to do this as a way to obtain a concise syntax for 
> manipulating a tree of elements deserialized at runtime, ex:
> data["foo"]["bar"] = "baz";
> assert( data["foo"]["bar"] == "baz" );
> foreach( subtree; data["foo"] )
>     doSubtreeOp( subtree );
>
> Having to place .get!(Variant[]) between each dereference will 
> defeat my use case.
>
> Associative arrays fail in the same way, btw.  I'm using 
> integers in the first example because it should be simpler to 
> get those right.
>
> I expected this to work because the value of 'ender[0]' will be 
> a variant that contains an array, and such a variant should be 
> able to index the contained array because of its opIndex 
> overload.

if this is a tree anyway better use custom node types.
so why not do this and overload opindex? unlike c++ u can put 
anything as key. i can't say from this example what types you are 
going to use but if it's only strings this should be very easy to 
implement.



More information about the Digitalmars-d-learn mailing list