View source code
Display the source code in std/meta.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Alias std.meta.Alias
Allows alias
ing of any single symbol, type or compile-time expression.
alias Alias(alias a)
= a;
alias Alias(T)
= T;
Not everything can be directly aliased. An alias cannot be declared of - for example - a literal:
alias a = 4; //Error
With this template any single entity can be aliased:
alias b = Alias!4; //OK
See Also
To alias more than one thing at once, use AliasSeq
.
Example
// Without Alias this would fail if Args[0] was e.g. a value and
// some logic would be needed to detect when to use enum instead
alias Head(Args ...) = Alias!(Args[0]);
alias Tail(Args ...) = Args[1 .. $];
alias Blah = AliasSeq!(3, int, "hello");
static assert(Head!Blah == 3);
static assert(is(Head!(Tail!Blah) == int));
static assert((Tail!Blah)[1] == "hello");
Example
alias a = Alias!(123);
static assert(a == 123);
enum abc = 1;
alias b = Alias!(abc);
static assert(b == 1);
alias c = Alias!(3 + 4);
static assert(c == 7);
alias concat = (s0, s1) => s0 ~ s1;
alias d = Alias!(concat("Hello", " World!"));
static assert(d == "Hello World!");
alias e = Alias!(int);
static assert(is(e == int));
alias f = Alias!(AliasSeq!(int));
static assert(!is(typeof(f[0]))); //not an AliasSeq
static assert(is(f == int));
auto g = 6;
alias h = Alias!g;
++h;
writeln(g); // 7
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.