T[#] can be a type or an array of types
Koroskin Denis
2korden at gmail.com
Wed Jun 4 02:18:54 PDT 2008
On Wed, 04 Jun 2008 05:49:55 +0400, BCS <ao at pathlink.com> wrote:
> not exactly a bug but this is a little weird.
>
>
> void Foo(alias Tfn)()
> {
> Tfn!()[2] x = void;
> pragma(msg,typeof(x).stringof);
> x[0] = Tfn!().init;
> }
>
> template Bob() { alias T!(int, uint, char) Bob; }
> template Joe() { alias int Joe; }
>
>
> template T(t...){alias t T;}
>
> alias Foo!(Bob) fig;
> alias Foo!(Joe) fig;
>
> void main(){}
>
>
Don't hesitate to post expected and actual output as well.
Let's look at the simplified version of Foo, first:
void Foo(alias Tfn)()
{
Tfn!() x;
pragma(msg,typeof(x).stringof);
}
It produces the following ouput (two template instantiations):
1) (int, uint, char) // ValueTuple!(int, uint, char), see std.typecons
for ValueTuple definition
2) int // int
Reverting back we get the following output:
1) char // ValueTuple!(int, uint, char)[2] -> char
2) int[2u] // int[2]
Did you expect to get a static array of Value tuples here instead of char?
Well, there is some kind of an ambiguity, how do tread ValueTuple!(int,
uint, char)[2]:
as an array of ValueTuples, or as a third type in a type-list? The latter
of takes precedence here.
Solution? You Tuple!(int, uint, char) instead (see std.typecons for Tuple
introduction):
import std.typecons;
Tuple!(int, uint, char) x0;
pragma(msg, typeof(x0).stringof); // prints: Tuple!(int,uint,char)
Tuple!(int, uint, char)[2] x1;
pragma(msg, typeof(x1).stringof); // prints: Tuple!(int,uint,char)[2u]
ValueTuple!(int, uint, char)[2] x2;
pragma(msg, typeof(x2).stringof); // prints: char
More information about the Digitalmars-d-bugs
mailing list