Skip to content

Commit 50323a6

Browse files
committed
Update getAliasThis documentation for dlang/dmd#9016
1 parent 83a1aa6 commit 50323a6

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

spec/traits.dd

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,35 @@ writeln(__traits(identifier, var)); // "var"
630630

631631
$(H2 $(GNAME getAliasThis))
632632

633-
$(P Takes one argument, a symbol of aggregate type.
634-
If the given aggregate type has $(D alias this), returns a list of
635-
$(D alias this) names, by a tuple of $(D string)s.
636-
Otherwise returns an empty tuple.
633+
$(P Takes one argument, a type. If the type has `alias this` declarations,
634+
returns a sequence of the names (as `string`s) of the members used in
635+
those declarations. Otherwise returns an empty sequence.
637636
)
638637

638+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
639+
---
640+
alias AliasSeq(T...) = T;
641+
642+
struct S1
643+
{
644+
string var;
645+
alias var this;
646+
}
647+
static assert(__traits(getAliasThis, S1) == AliasSeq!("var"));
648+
static assert(__traits(getAliasThis, int).length == 0);
649+
650+
pragma(msg, __traits(getAliasThis, S1));
651+
pragma(msg, __traits(getAliasThis, int));
652+
---
653+
)
654+
655+
Prints:
656+
657+
$(CONSOLE
658+
tuple("var")
659+
tuple()
660+
)
661+
639662
$(SECTION2 $(GNAME getAttributes),
640663
$(P
641664
Takes one argument, a symbol. Returns a tuple of all attached user-defined attributes.

0 commit comments

Comments
 (0)