digitalmars.D.learn - TypeTuple!(T...) vs Tuple!(T...)
- rsw0x (8/10) Jun 02 2015 exactly what is the difference here?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (11/20) Jun 02 2015 Tuple can hold only values, TypeTuple can hold types as well. Tuple can
- anonymous (5/11) Jun 02 2015 [...]
- Timon Gehr (2/11) Jun 02 2015 http://wiki.dlang.org/The_D_Programming_Language/Seq
- anonymous (14/19) Jun 02 2015 Almost.
- rsw0x (2/24) Jun 02 2015 That's... really confusing and probably needs a rewrite honestly.
- Atila Neves (3/33) Jun 02 2015 Yep.
- Alex Parrill (50/60) Jun 02 2015 Regular tuples are simply structs with a few methods like
- rsw0x (6/32) Jun 02 2015 I'm using a typetuple for data storage, if I replace it with a
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/6) Jun 02 2015 Also
- Dicebot (3/3) Jun 02 2015 I have PR for removing this obsolete article and replacing with
exactly what is the difference here? I have a rather large CTFE-generated TypeTuple in one of my structs in my project, and I can seemingly replace it with a Tuple with absolutely zero differences... except I compile about 60-70% slower. The tuple page is even confusing me http://dlang.org/tuple.htmlA variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On 06/02/2015 01:10 AM, rsw0x wrote:exactly what is the difference here? I have a rather large CTFE-generated TypeTuple in one of my structs in my project, and I can seemingly replace it with a Tuple with absolutely zero differences... except I compile about 60-70% slower. The tuple page is even confusing me http://dlang.org/tuple.htmlTuple can hold only values, TypeTuple can hold types as well. Tuple can be created at run time, TypeTuple is a compile-time concept. My guess is that your TypeTuple consists only of values. That's why they work the same. I have two sections about TypeTuples here: http://ddili.org/ders/d.en/tuples.html#ix_tuples.TypeTuple,%20std.typetuple http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.tuple%20template%20parameter AliA variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On Tuesday, 2 June 2015 at 09:34:28 UTC, Ali Çehreli wrote:On 06/02/2015 01:10 AM, rsw0x wrote:[...][...]The tuple page is even confusing me http://dlang.org/tuple.htmlTuple can hold only values, TypeTuple can hold types as well. Tuple can be created at run time, TypeTuple is a compile-time concept.You're using the phobos names here, i.e. `std.typecons.Tuple` and `std.typetuple.TypeTuple`. The article doesn't.
Jun 02 2015
On 06/02/2015 10:10 AM, rsw0x wrote:exactly what is the difference here? I have a rather large CTFE-generated TypeTuple in one of my structs in my project, and I can seemingly replace it with a Tuple with absolutely zero differences... except I compile about 60-70% slower. The tuple page is even confusing me http://dlang.org/tuple.htmlhttp://wiki.dlang.org/The_D_Programming_Language/SeqA variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On Tuesday, 2 June 2015 at 08:10:27 UTC, rsw0x wrote:The tuple page is even confusing me http://dlang.org/tuple.htmlAlmost. `Tuple` is defined at the top of the article as `template Tuple(E...) {alias Tuple = E;}`. "TypeTuple" is later defined as a `Tuple` whose elements "elements are solely types". So, in the context of the article, `Tuple!(int, long)` is a "TypeTuple", because it's a `Tuple` of types. The article does not refer to `std.typecons.Tuple` or `std.typetuple.TypeTuple` at all. Specifically, the article's `Tuple` is not `std.typecons.Tuple`. And the article's "TypeTuple" is not `std.typetuple.TypeTuple`. However, going for bonus confusion points, the article's `Tuple` is defined the same as `std.typetuple.TypeTuple`.A variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On Tuesday, 2 June 2015 at 11:49:18 UTC, anonymous wrote:On Tuesday, 2 June 2015 at 08:10:27 UTC, rsw0x wrote:That's... really confusing and probably needs a rewrite honestly.The tuple page is even confusing me http://dlang.org/tuple.htmlAlmost. `Tuple` is defined at the top of the article as `template Tuple(E...) {alias Tuple = E;}`. "TypeTuple" is later defined as a `Tuple` whose elements "elements are solely types". So, in the context of the article, `Tuple!(int, long)` is a "TypeTuple", because it's a `Tuple` of types. The article does not refer to `std.typecons.Tuple` or `std.typetuple.TypeTuple` at all. Specifically, the article's `Tuple` is not `std.typecons.Tuple`. And the article's "TypeTuple" is not `std.typetuple.TypeTuple`. However, going for bonus confusion points, the article's `Tuple` is defined the same as `std.typetuple.TypeTuple`.A variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On Tuesday, 2 June 2015 at 18:48:16 UTC, rsw0x wrote:On Tuesday, 2 June 2015 at 11:49:18 UTC, anonymous wrote:Yep. AtilaOn Tuesday, 2 June 2015 at 08:10:27 UTC, rsw0x wrote:That's... really confusing and probably needs a rewrite honestly.The tuple page is even confusing me http://dlang.org/tuple.htmlAlmost. `Tuple` is defined at the top of the article as `template Tuple(E...) {alias Tuple = E;}`. "TypeTuple" is later defined as a `Tuple` whose elements "elements are solely types". So, in the context of the article, `Tuple!(int, long)` is a "TypeTuple", because it's a `Tuple` of types. The article does not refer to `std.typecons.Tuple` or `std.typetuple.TypeTuple` at all. Specifically, the article's `Tuple` is not `std.typecons.Tuple`. And the article's "TypeTuple" is not `std.typetuple.TypeTuple`. However, going for bonus confusion points, the article's `Tuple` is defined the same as `std.typetuple.TypeTuple`.A variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On Tuesday, 2 June 2015 at 08:10:27 UTC, rsw0x wrote:exactly what is the difference here? I have a rather large CTFE-generated TypeTuple in one of my structs in my project, and I can seemingly replace it with a Tuple with absolutely zero differences... except I compile about 60-70% slower. The tuple page is even confusing me http://dlang.org/tuple.htmlRegular tuples are simply structs with a few methods like opIndex. Ex. `Tuple!(A,B,C)` is mostly equivalent to `struct { A _0; B _1; C _2; }`. TypeTuples (whose name is IMO a misnomer) are special compile-time-only objects whose values are passed in the template parameters and can be types, aliases, or literal values. They aren't first-class types, and shouldn't be used as data storage, but they do have some unique properties that make them useful for metaprogramming. Here's a small demonstration of TypeTuples: import std.stdio; import std.typetuple; void foo(int x, int y, int z) { writefln("x = %d, y = %d, z = %d", x, y, z); } void main() { int a, b, c; // Declare `vars` to be a typetuple containing aliases to a,b,c alias vars = TypeTuple!(a, b, c); vars[0] = 1; // Actually assign to a, b, c vars[1] = 2; vars[2] = 3; foo(a,b,c); foo(vars); // Same as above call alias test_values = TypeTuple!(123, 456, 789); foo(test_values); // Same as foo(123, 456, 7890) // won't work; test_values[0] is a literal and can't be assigned to. //test_values[0] = 321; foreach(ref some_var; vars) { // static foreach; this loop body is unrolled for each item in vars. some_var += 5; } foo(vars); } Output: $ rdmd ~/test.d x = 1, y = 2, z = 3 x = 1, y = 2, z = 3 x = 123, y = 456, z = 789 x = 6, y = 7, z = 8A variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On Tuesday, 2 June 2015 at 14:07:20 UTC, Alex Parrill wrote:On Tuesday, 2 June 2015 at 08:10:27 UTC, rsw0x wrote:I'm using a typetuple for data storage, if I replace it with a Tuple as I said in the OP, my program compiles 60-70% slower on all three compilers. But it seems to be working just fine as is, which is why I'm confused. I'm going to read Ali's links and maybe get a better understanding here.exactly what is the difference here? I have a rather large CTFE-generated TypeTuple in one of my structs in my project, and I can seemingly replace it with a Tuple with absolutely zero differences... except I compile about 60-70% slower. The tuple page is even confusing me http://dlang.org/tuple.htmlRegular tuples are simply structs with a few methods like opIndex. Ex. `Tuple!(A,B,C)` is mostly equivalent to `struct { A _0; B _1; C _2; }`. TypeTuples (whose name is IMO a misnomer) are special compile-time-only objects whose values are passed in the template parameters and can be types, aliases, or literal values. They aren't first-class types, and shouldn't be used as data storage, but they do have some unique properties that make them useful for metaprogramming. ...A variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long);is it using Tuple!(T...) and TypeTuple!(T...) interchangeably?
Jun 02 2015
On 06/02/2015 11:52 AM, rsw0x wrote:I'm going to read Ali's links and maybe get a better understanding here.Also https://github.com/PhilippeSigaud/D-templates-tutorial Ali
Jun 02 2015
I have PR for removing this obsolete article and replacing with more up to date one : https://github.com/D-Programming-Language/dlang.org/pull/986
Jun 02 2015