Why TypeTuple can be assigned to a variable

Simen Kjaeraas simen.kjaras at gmail.com
Wed Jun 12 03:08:49 PDT 2013


On Wed, 12 Jun 2013 11:44:19 +0200, Zhenya <zheny at list.ru> wrote:

> OK,you say that TypeTuple!("foo","bar") is a cool value of type
> TypeTuple!(string,string),right?

Well, yes and no, not really. It's a bit magical. In your case,
it's assigned to an auto variable, and that variable gets that type.
There are other ways to use a TypeTuple where it has other semantics,
as you write yourself.

As explained below, a TypeTuple is just a bag of template parameters,
and thus obeys the rules for a bag of template parameters.


> This behaviour confuses me a bit.

Understandable. It's not entirely straightforward, because the
concerns of usability weigh heavier than those of consistency.


> 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.

The definition od std.typetuple.TypeTuple is:

template TypeTuple(T...){
     alias TypeTuple = T;
}

So a TypeTuple is exactly the same as a variadic template
parameter pack.


> Sorry for my english.

No need to be, your English is great.

-- 
Simen


More information about the Digitalmars-d-learn mailing list