dmd/changelog/alias_from_trait.dd

27 lines
969 B
Text

Aliases can be created directly from a `__trait`.
Aliases can be created directly from the traits that return symbol(s) or tuples.
This includes `getMember`, `allMembers`, `derivedMembers`, `parent`, `getOverloads`,
`getVirtualFunctions`, `getVirtualMethods`, `getUnitTests`, `getAttributes` and finally `getAliasThis`.
Previously an `AliasSeq` was necessary in order to alias their return.
Now the grammar allows to write shorter declarations:
---
struct Foo
{
static int a;
}
alias oldWay = AliasSeq!(__traits(getMember, Foo, "a"))[0];
alias newWay = __traits(getMember, Foo, "a");
---
To permit this it was more interesting to include `__trait` in the basic types
rather than just changing the alias syntax. So additionally, wherever a type appears
a `__trait` can be used, for example in a variable declaration:
---
struct Foo { static struct Bar {} }
const(__traits(getMember, Foo, "Bar")) fooBar;
static assert(is(typeof(fooBar) == const(Foo.Bar)));
---