<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/8/21 Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a>></span><br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
I think this whole thread is approaching things wrongly. It should be:<br></div>
<br>
1. What do we need?<br></blockquote><div><br></div><div>Both</div><div>a. Built-in tuple construction syntax</div><div>and</div><div>b. Built-in tuple deconstruction syntax </div><div><br></div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2. What does a solution look like in the current language?<br></blockquote><div><br></div><div><div>a.</div><div>  alias Types = {int, long};</div><div>  auto values = {1, "str"};</div><div>b.</div><div>  auto {a, b} = tup;  // on variable declaration</div>
<div>  {a, b} = tup;       // on assignment expression</div><div>  ...</div></div><div><br></div><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
3. Which parts of the solution are frequent/cumbersome enough to warrant a language change?<br></blockquote><div><br></div><div><div>a1. To make std.typetuple.TypeTuple template unnecessary.</div><div>a2. To keep std.typecons.Tuple as-is.</div>
<div>a3. To make expression tuple more usable.</div><div><br></div><div>  Today making the built-in tuple of runtime values needs unavoidable runtime cost.</div><div><br></div><div>  int x, y;</div><div>  auto tup = TypeTuple!(x+1, y+2);</div>
<div>  // NG, template cannot take x+1 and y+2 because they are</div><div>  // expressions which cannot be evaluated in compile time</div><div>  auto tup = tuple(x+1, y+2);</div><div>  // NG, tup is not a builti-in tuple (it is an object of std.typecons.Tuple struct).</div>
<div>  auto tup = tuple(x+1, y+2).expand;</div><div>  // OK, tup is a builti-in tuple. But we cannot avoid the cost to pack in std.typecons.Tuple.</div><div><br></div><div>  Built-in tuple syntax would solve the issue.</div>
<div><br></div><div>  auto tup = {x+1, y+2};</div><div>  // tup is a built-in tuple, and it would be equivalent with:</div><div>  // auto tup[0] = x+1, tup[1] = x*2; // pseudo code</div></div><div>  // so no packing cost in runtime is there.</div>
<div><br></div><div>b.</div><div>  To make deconstruction code more readable.</div><div><br></div><div>  auto tup = std.typecons.tuple(1, "str");</div><div>  auto a = tup[0], b = tup[1];    // Currrent:</div><div>
  // Deconstruct two fields in tup to the two variables a and b</div><div>  auto {a, b} = tup;    // New syntax:</div><div>  // Deconstruct syntax would recognize alias this tuple,</div><div>  // and expand it automatically.</div>
<div><br></div><div>Kenji Hara</div></div></div></div>