On Wednesday, 12 June 2013 at 08:14:06 UTC, Simen Kjaeraas wrote:
On Wed, 12 Jun 2013 10:01:59 +0200, Zhenya <zh...@list.ru>
wrote:
Hi!
I was just surprised when realized, that this code compiles
and runs:
import std.typetuple;
import std.stdio;
void main()
{
auto foo = TypeTuple!("foo","bar");
writeln(typeid(typeof(foo)));
writeln(foo);
}
If I were compiler expert,I'd say that it's a bug.But I am not)
So, can anybody explain why it's work?
It is the equivalent of:
TypeTuple!(string, string) foo;
foo[0] = "foo";
foo[1] = "bar";
The ability to have a tupetuple as a variable is very useful -
if that
had not been possible one would need something akin to this:
struct Tuple(T...) {
T[0] head;
static if (T.length) {
Tuple!(T[1..$]) tail;
}
}
And to access the third element of a tuple one'd need to write:
myTuple.tail.tail.head = "foo";
Clearly this is suboptimal, so D has better ways of doing such
things.
OK,you say that TypeTuple!("foo","bar") is a cool value of type
TypeTuple!(string,string),right?
Then could you tell me what type has [TypeTuple!("foo","bar")]?
Currently it is evaluated to string[].And I think if TypeTuple
had value semantic, this type would be TypeTuple!(...)[].
This behaviour confuses me a bit.
And I just don't understand why do we need TypeTuple's value
semantic
to implement std.Tuple,because AFAIK it use variadic template
parameter pack
!= TypeTuple.
Sorry for my english.