How is `auto` and not `alias` appropriate for alias sequences?
ZombineDev via Digitalmars-d
digitalmars-d at puremagic.com
Fri Dec 11 06:53:30 PST 2015
On Friday, 11 December 2015 at 14:12:16 UTC, ZombineDev wrote:
> [...]
In short, the current D terminology calls:
compile-time lists -> AliasSeq
(http://dlang.org/phobos/std_meta#AliasSeq)
run-time values of type lists -> Tuple
(http://dlang.org/phobos/std_typecons#.Tuple)
Another example:
Tuple!(int, string)(3, "apples") obj;
obj is a run-time tuple of the integer 3 and the string "apples".
The template arguments int and string are a type list (and a
special case of an alias sequence).
alias Point2D = Tuple!(int, "x", int, "" ~ 'y');
auto point_a = Point2D(3, 4);
auto point_b = Point2D(1, -7);
Point2D is an alias to the type Tuple!(int, "x", int, "" ~ 'y'),
which is a template instance of the Tuple(Specs...) template.
The (int, "x", int, "" ~ 'y') template arguments have both types
and compile-time expressions among them and that's why we call it
an alias sequence and not just a type list.
point_a and point_b are tuples of two ints and are run-time
values.
You can put the template arguments used for Point2D in a AliasSeq:
alias Point3DTemplateArgs = AliasSeq!(float, "x", int, "y",
double, "z");
And you can use those template args to make a new instance of the
Tuple template:
alias Point3D = Tuple!(Point3DTemplateArgs);
Some runtime values can also be computed at compile-time and you
can use them for enums.
http://dpaste.dzfl.pl/a05cf181331d (I think that only the output
of "2:" is inconsistent.)
Also I found this article, which maybe helpful:
http://dlang.org/ctarguments.html
More information about the Digitalmars-d
mailing list