Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 18, 2012 Need help understanding Tuple | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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); } |
December 18, 2012 Re: Need help understanding Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to d coder | 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
|
December 18, 2012 Re: Need help understanding Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile Attachments:
| > 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); } |
December 18, 2012 Re: Need help understanding Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to d coder | 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 |
December 18, 2012 Re: Need help understanding Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Chapman Attachments:
| > The spec goes into tuples in some depth: http://dlang.org/tuple.html
>
Thanks John.
|
Copyright © 1999-2021 by the D Language Foundation