Skip to content

Commit 3c3e51a

Browse files
authored
[spec] Tweak template alias parameter docs (#3421)
Add 2 subheadings. Make examples runnable.
1 parent 38df936 commit 3c3e51a

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

spec/template.dd

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,17 @@ $(GNAME TemplateAliasParameterDefault):
583583

584584
$(P Alias parameters enable templates to be parameterized with
585585
symbol names or values computed at compile-time.
586-
Almost any kind of D symbol can be used, including user-defined type names,
586+
Almost any kind of D symbol can be used, including type names,
587587
global names, local names, module names, template names, and
588-
template instance names.
588+
template instances.
589589
)
590590

591-
$(P $(B Symbol examples:))
591+
$(H4 $(LNAME2 alias_symbol, Symbol Aliases))
592592

593593
$(UL
594-
$(LI User-defined type names
594+
$(LI Type names
595595

596+
$(SPEC_RUNNABLE_EXAMPLE_RUN
596597
------
597598
class Foo
598599
{
@@ -608,12 +609,15 @@ $(GNAME TemplateAliasParameterDefault):
608609
{
609610
alias bar = Bar!(Foo);
610611
bar.sym = 3; // sets Foo.x to 3
612+
assert(Foo.x == 3);
611613
}
612614
------
613615
)
616+
)
614617

615618
$(LI Global names
616619

620+
$(SPEC_RUNNABLE_EXAMPLE_RUN
617621
------
618622
shared int x;
619623

@@ -626,14 +630,19 @@ $(GNAME TemplateAliasParameterDefault):
626630
{
627631
alias bar = Foo!(x);
628632
*bar.ptr = 3; // set x to 3
633+
assert(x == 3);
634+
629635
static shared int y;
630636
alias abc = Foo!(y);
631637
*abc.ptr = 3; // set y to 3
638+
assert(y == 3);
632639
}
633640
------
634641
)
642+
)
635643

636644
$(LI Local names
645+
$(SPEC_RUNNABLE_EXAMPLE_RUN
637646
---
638647
template Foo(alias var)
639648
{
@@ -648,11 +657,13 @@ $(GNAME TemplateAliasParameterDefault):
648657
assert(v == 5);
649658
}
650659
---
660+
)
651661
See also $(RELATIVE_LINK2 implicit-nesting, Implicit Template Nesting).
652662
)
653663

654664
$(LI Module names
655665

666+
$(SPEC_RUNNABLE_EXAMPLE_RUN
656667
------
657668
import std.conv;
658669

@@ -664,13 +675,16 @@ $(GNAME TemplateAliasParameterDefault):
664675
void main()
665676
{
666677
alias bar = Foo!(std.conv);
667-
bar.sym(3); // calls std.conv.text(3)
678+
string s = bar.sym(3); // calls std.conv.text(3)
679+
assert(s == "3");
668680
}
669681
------
670682
)
683+
)
671684

672685
$(LI Template names
673686

687+
$(SPEC_RUNNABLE_EXAMPLE_RUN
674688
------
675689
shared int x;
676690

@@ -688,12 +702,15 @@ $(GNAME TemplateAliasParameterDefault):
688702
{
689703
alias bar = Bar!(Foo);
690704
*bar.instance.ptr = 3; // sets x to 3
705+
assert(x == 3);
691706
}
692707
------
693708
)
709+
)
694710

695711
$(LI Template instance names
696712

713+
$(SPEC_RUNNABLE_EXAMPLE_RUN
697714
------
698715
shared int x;
699716

@@ -712,12 +729,14 @@ $(GNAME TemplateAliasParameterDefault):
712729
alias foo = Foo!(x);
713730
alias bar = Bar!(foo);
714731
*bar.p = 3; // sets x to 3
732+
assert(x == 3);
715733
}
716734
------
717735
)
736+
)
718737
)
719738

720-
$(P $(B Value examples:))
739+
$(H4 $(LNAME2 alias_value, Value Aliases))
721740

722741
$(UL
723742

0 commit comments

Comments
 (0)