digitalmars.D.learn - Need help understanding Tuple
- d coder (20/20) Dec 18 2012 Greetings
- bearophile (6/19) Dec 18 2012 As first step, don't use that Tuple, use std.typetuple.TypeTuple
- d coder (14/16) Dec 18 2012 Thanks for the correction. Tuple is indeed confusing with
- John Chapman (3/12) Dec 18 2012 The spec goes into tuples in some depth:
- d coder (1/2) Dec 18 2012 Thanks John.
Greetings Somebody please help me understand why we need the Tuple template in the following code. Does not __traits(getAttributes, foo.a) return a tuple? So what is the Tuple template doing here? Converting a tuple to a tuple? Also where to learn more about tuples in D. Info in TDPL is sketchy. Regards - Puneet template Tuple(T...) { alias T Tuple; } enum Bar; class Foo { Bar int a; } void main() { Foo foo = new Foo; alias Tuple!(__traits(getAttributes, foo.a)) tp; pragma(msg, tp); }
Dec 18 2012
d coder:template Tuple(T...) { alias T Tuple; } enum Bar; class Foo { Bar int a; } void main() { Foo foo = new Foo; alias Tuple!(__traits(getAttributes, foo.a)) tp; pragma(msg, tp); }As first step, don't use that Tuple, use std.typetuple.TypeTuple instead. It's the same, but using the standardized name helps readability. Bye, bearophile
Dec 18 2012
As first step, don't use that Tuple, use std.typetuple.TypeTuple instead. It's the same, but using the standardized name helps readability.Thanks for the correction. Tuple is indeed confusing with std.typecons.Tuple which is a struct tuple. So here is the code again. enum Bar; class Foo { Bar int a; } void main() { import std.typetuple; Foo foo = new Foo; alias TypeTuple!(__traits(getAttributes, foo.a)) tp; pragma(msg, tp); }
Dec 18 2012
On Tuesday, 18 December 2012 at 11:06:12 UTC, d coder wrote:Greetings Somebody please help me understand why we need the Tuple template in the following code. Does not __traits(getAttributes, foo.a) return a tuple? So what is the Tuple template doing here? Converting a tuple to a tuple? Also where to learn more about tuples in D. Info in TDPL is sketchy.The spec goes into tuples in some depth: http://dlang.org/tuple.html
Dec 18 2012
The spec goes into tuples in some depth: http://dlang.org/tuple.htmlThanks John.
Dec 18 2012