@@ -2627,42 +2627,9 @@ int main(string[] args) { ... }
2627
2627
2628
2628
$(H2 $(LNAME2 function-templates, Function Templates))
2629
2629
2630
- $(P Template functions are useful for avoiding code duplication -
2631
- instead of writing several copies of a function, each with a
2632
- different parameter type, a single function template can be sufficient.
2633
- For example:
2634
- )
2635
-
2636
- $(SPEC_RUNNABLE_EXAMPLE_COMPILE
2637
- ---
2638
- // Only one copy of func needs to be written
2639
- void func(T)(T x)
2640
- {
2641
- writeln(x);
2642
- }
2643
- void main()
2644
- {
2645
- func!(int)(1); // pass an int
2646
- func(1); // pass an int, inferring T = int
2647
- func("x"); // pass a string
2648
- func(1.0); // pass a float
2649
- struct S {}
2650
- S s;
2651
- func(s); // pass a struct
2652
- }
2653
- ---
2654
- )
2655
-
2656
- $(P $(D func) takes a template parameter $(D T) and a runtime
2657
- parameter, $(D x). $(D T) is a placeholder identifier that can accept
2658
- any type. In this case $(D T) can be inferred from the runtime argument
2659
- type.)
2660
-
2661
- $(P $(B Note:) Using the name $(D T) is just a convention. The name
2662
- $(D TypeOfX) could have been used instead.)
2630
+ $(P Functions can have compile time arguments in the form of a template.
2631
+ See $(DDSUBLINK spec/template, function-templates, function templates).)
2663
2632
2664
- $(P For more information, see
2665
- $(DDSUBLINK spec/template, function-templates, function templates).)
2666
2633
2667
2634
$(H2 $(LNAME2 interpretation, Compile Time Function Execution (CTFE)))
2668
2635
0 commit comments