Re: ref tuples

2013-07-03 Thread Artur Skawina
On 07/03/13 02:22, Brad Anderson wrote: C++11's std::tuple includes a function std::tie that takes references to the arguments and returns a tuple that maintains the references to the arguments. Along with the usual cases where you'd want reference semantics it also enables this

Re: ref tuples

2013-07-03 Thread Dicebot
On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: Well, aliases can be used to get a similar effect. template tie(A...) { alias tie = A; } tie!(a, b) = tuple(1, 2); artur Which is actually already in Phobos: TypeTuple!(a, b) = tuple(1, 2);

Re: ref tuples

2013-07-03 Thread Artur Skawina
On 07/03/13 18:29, Brad Anderson wrote: On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: On 07/03/13 02:22, Brad Anderson wrote: C++11's std::tuple includes a function std::tie that takes references to the arguments and returns a tuple that maintains the references to the

Re: ref tuples

2013-07-03 Thread Brad Anderson
On Wednesday, 3 July 2013 at 16:35:18 UTC, Artur Skawina wrote: On 07/03/13 18:29, Brad Anderson wrote: On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: On 07/03/13 02:22, Brad Anderson wrote: C++11's std::tuple includes a function std::tie that takes references to the

Re: ref tuples

2013-07-03 Thread Simen Kjaeraas
On 2013-07-03, 02:22, Brad Anderson wrote: C++11's std::tuple includes a function std::tie that takes references to the arguments and returns a tuple that maintains the references to the arguments. Along with the usual cases where you'd want reference semantics it also enables this

Re: ref tuples

2013-07-03 Thread Artur Skawina
On 07/03/13 19:10, Brad Anderson wrote: On Wednesday, 3 July 2013 at 16:35:18 UTC, Artur Skawina wrote: On 07/03/13 18:29, Brad Anderson wrote: On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: On 07/03/13 02:22, Brad Anderson wrote: C++11's std::tuple includes a function

ref tuples

2013-07-02 Thread Brad Anderson
C++11's std::tuple includes a function std::tie that takes references to the arguments and returns a tuple that maintains the references to the arguments. Along with the usual cases where you'd want reference semantics it also enables this interesting construct for unpacking tuples. int a,

Re: Alias/Ref Tuples ?

2011-12-17 Thread Philippe Sigaud
On Sat, Dec 17, 2011 at 01:23, Simen Kjærås simen.kja...@gmail.com wrote: A few small tests later: import std.typetuple; import std.typecons; import std.stdio; void main() {    int a, b;    TypeTuple!(a, b) = tuple(4,5);    assert(a == 4 b == 5); } In other words, the language

Alias/Ref Tuples ?

2011-12-16 Thread Joshua Reusch
Hello, is there a way to say something like --- int a, b; AliasTuple!(a, b) = tuple(4,5); assert(a == 4 b == 5); --- without having to write an own AliasTuple template ? I want to use it for functions returning multiple values. Joshua Reusch

Re: Alias/Ref Tuples ?

2011-12-16 Thread Trass3r
I think something like this is implemented in a dmd pull request.

Re: Alias/Ref Tuples ?

2011-12-16 Thread Joshua Reusch
I found a way doing this with a simple function: --- void explode(R, T...)(R range, ref T values) { static if(hasLength!R) assert(range.length == T.length); foreach(i, value; range) values[i] = value; } --- but a more self-documenting version would be nice.

Re: Alias/Ref Tuples ?

2011-12-16 Thread Simen Kjærås
On Fri, 16 Dec 2011 14:00:11 +0100, Joshua Reusch yos...@arkandos.de wrote: Hello, is there a way to say something like --- int a, b; AliasTuple!(a, b) = tuple(4,5); assert(a == 4 b == 5); --- without having to write an own AliasTuple template ? I want to use it for functions returning

Re: Alias/Ref Tuples ?

2011-12-16 Thread Philippe Sigaud
There is one in dranges: http://dsource.org/projects/dranges It is not officially documented, and I don't know how good it actually is, but here's what documentation exists: http://svn.dsource.org/projects/dranges/trunk/dranges/docs/reftuple.html Hmm, thanks Simen, but no. It was a simple

Re: Alias/Ref Tuples ?

2011-12-16 Thread Simen Kjærås
On Fri, 16 Dec 2011 14:00:11 +0100, Joshua Reusch yos...@arkandos.de wrote: Hello, is there a way to say something like --- int a, b; AliasTuple!(a, b) = tuple(4,5); assert(a == 4 b == 5); --- without having to write an own AliasTuple template ? I want to use it for functions returning

Re: Alias/Ref Tuples ?

2011-12-16 Thread Joshua Reusch
Am 17.12.2011 01:23, schrieb Simen Kjærås: On Fri, 16 Dec 2011 14:00:11 +0100, Joshua Reusch yos...@arkandos.de wrote: Hello, is there a way to say something like --- int a, b; AliasTuple!(a, b) = tuple(4,5); assert(a == 4 b == 5); --- without having to write an own AliasTuple template ? I