Skip to content

Commit 8e32471

Browse files
authored
Merge pull request #2517 from n8sh/issue-19439
Update getAliasThis documentation per issue 19439 merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2 parents 2f8d178 + 50323a6 commit 8e32471

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
@@ -646,12 +646,35 @@ writeln(__traits(identifier, var)); // "var"
646646

647647
$(H2 $(GNAME getAliasThis))
648648

649-
$(P Takes one argument, a symbol of aggregate type.
650-
If the given aggregate type has $(D alias this), returns a list of
651-
$(D alias this) names, by a tuple of $(D string)s.
652-
Otherwise returns an empty tuple.
649+
$(P Takes one argument, a type. If the type has `alias this` declarations,
650+
returns a sequence of the names (as `string`s) of the members used in
651+
those declarations. Otherwise returns an empty sequence.
653652
)
654653

654+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
655+
---
656+
alias AliasSeq(T...) = T;
657+
658+
struct S1
659+
{
660+
string var;
661+
alias var this;
662+
}
663+
static assert(__traits(getAliasThis, S1) == AliasSeq!("var"));
664+
static assert(__traits(getAliasThis, int).length == 0);
665+
666+
pragma(msg, __traits(getAliasThis, S1));
667+
pragma(msg, __traits(getAliasThis, int));
668+
---
669+
)
670+
671+
Prints:
672+
673+
$(CONSOLE
674+
tuple("var")
675+
tuple()
676+
)
677+
655678
$(SECTION2 $(GNAME getAttributes),
656679
$(P
657680
Takes one argument, a symbol. Returns a tuple of all attached user-defined attributes.

0 commit comments

Comments
 (0)