digitalmars.D.learn - Merge tuples
- simendsjo (8/8) May 31 2012 This is probably very simple, but I cannot find out how to do it..
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (6/14) May 31 2012 Just look at std.typecons.Tuple.
-
simendsjo
(7/19)
May 31 2012
On Thu, 31 May 2012 16:54:53 +0200, Alex R=C3=B8nne Petersen
- bearophile (5/11) May 31 2012 ToTuple will have a hard time inventing the names for those
- simendsjo (4/16) May 31 2012 Not sure I understand what you mean. Using Variables[i].stringof in a
- Philippe Sigaud (25/36) May 31 2012 Is the following what you're looking for?
This is probably very simple, but I cannot find out how to do it.. I have several variables, and want to construct a tuple for the values. int a; string b; ToTuple!(a, b) should create Tuple!(int, "a", string, "b") template ToTuple(Variables...) { ? }
May 31 2012
On 31-05-2012 16:53, simendsjo wrote:This is probably very simple, but I cannot find out how to do it.. I have several variables, and want to construct a tuple for the values. int a; string b; ToTuple!(a, b) should create Tuple!(int, "a", string, "b") template ToTuple(Variables...) { ? }Just look at std.typecons.Tuple. -- Alex Rønne Petersen alex lycus.org http://lycus.org
May 31 2012
On Thu, 31 May 2012 16:54:53 +0200, Alex R=C3=B8nne Petersen <alex lycus= .org> = wrote:On 31-05-2012 16:53, simendsjo wrote:s.This is probably very simple, but I cannot find out how to do it.. I have several variables, and want to construct a tuple for the value=I did, but I don't know how to lower it so I don't get tuples of tuples:= = Tuple!(int,"a"c,Tuple!(string,"b"c))int a; string b; ToTuple!(a, b) should create Tuple!(int, "a", string, "b") template ToTuple(Variables...) { ? }Just look at std.typecons.Tuple.
May 31 2012
simendsjo:int a; string b; ToTuple!(a, b) should create Tuple!(int, "a", string, "b") template ToTuple(Variables...) { ? }ToTuple will have a hard time inventing the names for those fields... Bye, bearophile
May 31 2012
On Thu, 31 May 2012 18:42:20 +0200, bearophile <bearophileHUGS lycos.com> wrote:simendsjo:Not sure I understand what you mean. Using Variables[i].stringof in a template gives the original name.int a; string b; ToTuple!(a, b) should create Tuple!(int, "a", string, "b") template ToTuple(Variables...) { ? }ToTuple will have a hard time inventing the names for those fields... Bye, bearophile
May 31 2012
On Thu, May 31, 2012 at 7:14 PM, simendsjo <simendsjo gmail.com> wrote:On Thu, 31 May 2012 18:42:20 +0200, bearophile <bearophileHUGS lycos.com> wrote:Is the following what you're looking for? import std.stdio; import std.typecons; import std.typetuple; template TypeAndName(Variables...) { static if (Variables.length =3D=3D 0) alias TypeTuple!() TypeAndName; else alias TypeTuple!(typeof(Variables[0]), Variables[0].stringof, TypeAndName!(Variables[1..$])) TypeAndName; } Tuple!(TypeAndName!(Variables)) toTuple(Variables...)() property { return Tuple!(TypeAndName!(Variables))(Variables); } void main() { int i =3D 1; double d =3D 3.14; auto t =3D toTuple!(i,d); writeln(t.i); writeln(t.d); }simendsjo:int a; string b; ToTuple!(a, b) should create Tuple!(int, "a", string, "b") template ToTuple(Variables...) { =C2=A0? }
May 31 2012