<div dir="ltr">Try this:<div>```</div><div><div>import std.typecons;</div><div>import std.typetuple;</div><div>import std.math;</div><div>import std.stdio;</div><div><br></div><div>auto tie(StoreElements...)(ref StoreElements stores)</div>
<div>{</div><div><span class="" style="white-space:pre">    </span>alias Elements = staticMap!(Unqual, StoreElements);</div><div><span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">   </span>template toPointer(T)</div>
<div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span>alias toPointer = T*;</div><div><span class="" style="white-space:pre">      </span>}</div><div><span class="" style="white-space:pre">  </span></div>
<div><span class="" style="white-space:pre">    </span>struct Holder</div><div><span class="" style="white-space:pre">      </span>{</div><div><span class="" style="white-space:pre">          </span>alias StoreElementsPtrs = staticMap!(toPointer, StoreElements);</div>
<div><span class="" style="white-space:pre">            </span>StoreElementsPtrs storePtrs;</div><div><span class="" style="white-space:pre">               </span></div><div><span class="" style="white-space:pre">           </span>this(ref StoreElements stores)</div>
<div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span>foreach(i, _; StoreElements)</div><div><span class="" style="white-space:pre">                       </span>{</div><div><span class="" style="white-space:pre">                          </span>storePtrs[i] = &stores[i];</div>
<div><span class="" style="white-space:pre">                    </span>}</div><div><span class="" style="white-space:pre">          </span>}</div><div><span class="" style="white-space:pre">          </span></div><div><span class="" style="white-space:pre">           </span>void opAssign(Tuple!Elements values)</div>
<div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span>foreach(i, _; Elements)</div><div><span class="" style="white-space:pre">                    </span>{</div><div><span class="" style="white-space:pre">                          </span>*storePtrs[i] = values[i];</div>
<div><span class="" style="white-space:pre">                    </span>}</div><div><span class="" style="white-space:pre">          </span>}</div><div><span class="" style="white-space:pre">  </span>}</div><div><span class="" style="white-space:pre">  </span></div>
<div><span class="" style="white-space:pre">    </span>return Holder(stores);</div><div>}</div><div><br></div><div>Tuple!(float, float) sinCos(float n) </div><div>{</div><div><span class="" style="white-space:pre">       </span>return tuple(cast(float)sin(n), cast(float)cos(n)); //please note cast(float)!</div>
<div>}</div><div><br></div><div>void main() </div><div>{</div><div><span class="" style="white-space:pre">       </span>float s,c;</div><div><span class="" style="white-space:pre"> </span>tie(s,c) = sinCos(3.0f);  </div><div><span class="" style="white-space:pre">        </span>writeln(s, " ", c);</div>
<div>}</div></div><div>```</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-08 22:55 GMT+04:00 Meta via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tuesday, 8 July 2014 at 18:45:21 UTC, Remo wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tuesday, 8 July 2014 at 18:29:40 UTC, Meta wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tuesday, 8 July 2014 at 17:42:00 UTC, Remo wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
How to make something that work like std::tie in D2 ?<br>
<br>
Tuple!(float, float) sinCos(float n) {<br>
return tuple(cast(float)sin(n), cast(float)cos(n)); //please note cast(float)!<br>
}<br>
<br>
int main(string[] argv) {<br>
float s,c;<br>
tie!(s,c) = sinCos(3.0f);<br>
}<br>
</blockquote>
<br>
alias tie = TypeTuple;<br>
<br>
int main(string[] argv)<br>
{<br>
   float s,c;<br>
   tie!(s,c) = sinCos(3.0f);<br>
}<br>
</blockquote>
<br>
Thanks !<br>
This is easier as I was thinking :)<br>
Now I only need to be sure that this do not have unwanted side effects.<br>
</blockquote>
<br></div></div>
It's fine. There's not much to TypeTuple; it's defined like this:<br>
<br>
alias TypeTuple(TList...) = alias TypeTuple = TList;<br>
<br>
Where TList is any number of... things. Types, variables, values, template names, etc. Therefore, `TypeTuple!(s, c)` at a low level it's more or less like the following:<br>
<br>
float s, c;<br>
<br>
s = sinCos(3.0f)[0];<br>
c = sinCos(3.0f)[1];<br>
<br>
Not that sinCos is called twice. It's only called once, and the result is distributed across s and c.<br>
</blockquote></div><br></div>