On Wed, Jun 12, 2013 at 5:38 AM, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 6/12/13 5:38 AM, Timothee Cour wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
However I've implemented something that works exactly as required:<br>
<br>
<a href="https://github.com/timotheecour/dtools/blob/master/dtools/util/variant_nested.d" target="_blank">https://github.com/<u></u>timotheecour/dtools/blob/<u></u>master/dtools/util/variant_<u></u>nested.d</a><br>
<br>
         auto<br>
d=variantTupleNamed("a",1,"b",<u></u>"foo","c",variantTuple(1,2.2,"<u></u>three"));<br>
</blockquote>
<br></div>
Do calls to variantTupleNamed nest within one another? This seems interesting. We should integrate this with json I/O as well.<span class="HOEnZb"><font color="#888888"><br>
<br>
Andrei<br>
</font></span></blockquote></div><br><div>Yes, the base type Variant2 nests recursively.</div><div><br></div><div>I've added this to the unittest:</div><div><br></div><div><div>                Variant2 a1=0;</div><div>
<span class="Apple-tab-span" style="white-space:pre">         </span>a1=variantTuple(1,"a");</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>a1[0]=variantTuple("foo",1.1);</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>auto a2=variantTuple(3,[1]);</div>
<div><span class="Apple-tab-span" style="white-space:pre">              </span>a1[1]=a2;</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>a1~="foo2";</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>assert(a1.text==`[[foo, 1.1], [3, [1]], foo2]`);</div>
</div><div><br></div><div>(variantTupleNamed is just a way to construct a named tuple, but works as variantTuple)</div><div><br></div><div>Further, see my comment "read-modify-write works": I would think this could be applied to std.variant.Variant too.</div>
<div><br></div><div><br></div>