Try this: ``` import std.typecons; import std.typetuple; import std.math; import std.stdio;
auto tie(StoreElements...)(ref StoreElements stores) { alias Elements = staticMap!(Unqual, StoreElements); template toPointer(T) { alias toPointer = T*; } struct Holder { alias StoreElementsPtrs = staticMap!(toPointer, StoreElements); StoreElementsPtrs storePtrs; this(ref StoreElements stores) { foreach(i, _; StoreElements) { storePtrs[i] = &stores[i]; } } void opAssign(Tuple!Elements values) { foreach(i, _; Elements) { *storePtrs[i] = values[i]; } } } return Holder(stores); } Tuple!(float, float) sinCos(float n) { return tuple(cast(float)sin(n), cast(float)cos(n)); //please note cast(float)! } void main() { float s,c; tie(s,c) = sinCos(3.0f); writeln(s, " ", c); } ``` 2014-07-08 22:55 GMT+04:00 Meta via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>: > On Tuesday, 8 July 2014 at 18:45:21 UTC, Remo wrote: > >> On Tuesday, 8 July 2014 at 18:29:40 UTC, Meta wrote: >> >>> On Tuesday, 8 July 2014 at 17:42:00 UTC, Remo wrote: >>> >>>> >>>> How to make something that work like std::tie in D2 ? >>>> >>>> Tuple!(float, float) sinCos(float n) { >>>> return tuple(cast(float)sin(n), cast(float)cos(n)); //please note >>>> cast(float)! >>>> } >>>> >>>> int main(string[] argv) { >>>> float s,c; >>>> tie!(s,c) = sinCos(3.0f); >>>> } >>>> >>> >>> alias tie = TypeTuple; >>> >>> int main(string[] argv) >>> { >>> float s,c; >>> tie!(s,c) = sinCos(3.0f); >>> } >>> >> >> Thanks ! >> This is easier as I was thinking :) >> Now I only need to be sure that this do not have unwanted side effects. >> > > It's fine. There's not much to TypeTuple; it's defined like this: > > alias TypeTuple(TList...) = alias TypeTuple = TList; > > 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: > > float s, c; > > s = sinCos(3.0f)[0]; > c = sinCos(3.0f)[1]; > > Not that sinCos is called twice. It's only called once, and the result is > distributed across s and c. >