@@ -583,16 +583,17 @@ $(GNAME TemplateAliasParameterDefault):
583
583
584
584
$(P Alias parameters enable templates to be parameterized with
585
585
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,
587
587
global names, local names, module names, template names, and
588
- template instance names .
588
+ template instances .
589
589
)
590
590
591
- $(P $(B Symbol examples: ))
591
+ $(H4 $(LNAME2 alias_symbol, Symbol Aliases ))
592
592
593
593
$(UL
594
- $(LI User-defined type names
594
+ $(LI Type names
595
595
596
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
596
597
------
597
598
class Foo
598
599
{
@@ -608,12 +609,15 @@ $(GNAME TemplateAliasParameterDefault):
608
609
{
609
610
alias bar = Bar!(Foo);
610
611
bar.sym = 3; // sets Foo.x to 3
612
+ assert(Foo.x == 3);
611
613
}
612
614
------
613
615
)
616
+ )
614
617
615
618
$(LI Global names
616
619
620
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
617
621
------
618
622
shared int x;
619
623
@@ -626,14 +630,19 @@ $(GNAME TemplateAliasParameterDefault):
626
630
{
627
631
alias bar = Foo!(x);
628
632
*bar.ptr = 3; // set x to 3
633
+ assert(x == 3);
634
+
629
635
static shared int y;
630
636
alias abc = Foo!(y);
631
637
*abc.ptr = 3; // set y to 3
638
+ assert(y == 3);
632
639
}
633
640
------
634
641
)
642
+ )
635
643
636
644
$(LI Local names
645
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
637
646
---
638
647
template Foo(alias var)
639
648
{
@@ -648,11 +657,13 @@ $(GNAME TemplateAliasParameterDefault):
648
657
assert(v == 5);
649
658
}
650
659
---
660
+ )
651
661
See also $(RELATIVE_LINK2 implicit-nesting, Implicit Template Nesting).
652
662
)
653
663
654
664
$(LI Module names
655
665
666
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
656
667
------
657
668
import std.conv;
658
669
@@ -664,13 +675,16 @@ $(GNAME TemplateAliasParameterDefault):
664
675
void main()
665
676
{
666
677
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");
668
680
}
669
681
------
670
682
)
683
+ )
671
684
672
685
$(LI Template names
673
686
687
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
674
688
------
675
689
shared int x;
676
690
@@ -688,12 +702,15 @@ $(GNAME TemplateAliasParameterDefault):
688
702
{
689
703
alias bar = Bar!(Foo);
690
704
*bar.instance.ptr = 3; // sets x to 3
705
+ assert(x == 3);
691
706
}
692
707
------
693
708
)
709
+ )
694
710
695
711
$(LI Template instance names
696
712
713
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
697
714
------
698
715
shared int x;
699
716
@@ -712,12 +729,14 @@ $(GNAME TemplateAliasParameterDefault):
712
729
alias foo = Foo!(x);
713
730
alias bar = Bar!(foo);
714
731
*bar.p = 3; // sets x to 3
732
+ assert(x == 3);
715
733
}
716
734
------
717
735
)
736
+ )
718
737
)
719
738
720
- $(P $(B Value examples: ))
739
+ $(H4 $(LNAME2 alias_value, Value Aliases ))
721
740
722
741
$(UL
723
742
0 commit comments