Skip to content

Commit ae9d2d6

Browse files
ntreldlang-bot
authored andcommitted
[spec/template] Move Type Parameters above Type Parameter Deduction
So specialization is described first. Only content change is making deduction a child of type parameters.
1 parent a1b9a22 commit ae9d2d6

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

spec/template.dd

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,48 @@ $(GNAME TemplateParameter):
277277
$(I TemplateParameter) when a matching argument is not supplied.
278278
)
279279

280-
$(H3 $(LNAME2 argument_deduction, Type Parameter Deduction))
280+
$(H3 $(LNAME2 template_type_parameters, Type Parameters))
281+
282+
$(GRAMMAR
283+
$(GNAME TemplateTypeParameter):
284+
$(GLINK_LEX Identifier)
285+
$(GLINK_LEX Identifier) $(GLINK TemplateTypeParameterSpecialization)
286+
$(GLINK_LEX Identifier) $(GLINK TemplateTypeParameterDefault)
287+
$(GLINK_LEX Identifier) $(GLINK TemplateTypeParameterSpecialization) $(GLINK TemplateTypeParameterDefault)
288+
289+
$(GNAME TemplateTypeParameterSpecialization):
290+
$(D :) $(GLINK2 type, Type)
291+
292+
$(GNAME TemplateTypeParameterDefault):
293+
$(D =) $(GLINK2 type, Type)
294+
)
295+
296+
$(H4 $(LNAME2 parameters_specialization, Specialization))
297+
298+
$(P Templates may be specialized for particular types of arguments
299+
by following the template parameter identifier with a : and the
300+
specialized type.
301+
For example:)
302+
303+
------
304+
template TFoo(T) { ... } // #1
305+
template TFoo(T : T[]) { ... } // #2
306+
template TFoo(T : char) { ... } // #3
307+
template TFoo(T, U, V) { ... } // #4
308+
309+
alias foo1 = TFoo!(int); // instantiates #1
310+
alias foo2 = TFoo!(double[]); // instantiates #2 with T being double
311+
alias foo3 = TFoo!(char); // instantiates #3
312+
alias fooe = TFoo!(char, int); // error, number of arguments mismatch
313+
alias foo4 = TFoo!(char, int, int); // instantiates #4
314+
------
315+
316+
$(P The template picked to instantiate is the one that is most specialized
317+
that fits the types of the $(I TemplateArgumentList).
318+
If the result is ambiguous, it is an error.
319+
)
320+
321+
$(H4 $(LNAME2 argument_deduction, Type Parameter Deduction))
281322

282323
$(P The types of template parameters are deduced for a particular
283324
template instantiation by comparing the template argument with
@@ -351,47 +392,6 @@ $(H3 $(LNAME2 argument_deduction, Type Parameter Deduction))
351392
// (3) U is B
352393
------
353394

354-
$(H3 $(LNAME2 template_type_parameters, Type Parameters))
355-
356-
$(GRAMMAR
357-
$(GNAME TemplateTypeParameter):
358-
$(GLINK_LEX Identifier)
359-
$(GLINK_LEX Identifier) $(GLINK TemplateTypeParameterSpecialization)
360-
$(GLINK_LEX Identifier) $(GLINK TemplateTypeParameterDefault)
361-
$(GLINK_LEX Identifier) $(GLINK TemplateTypeParameterSpecialization) $(GLINK TemplateTypeParameterDefault)
362-
363-
$(GNAME TemplateTypeParameterSpecialization):
364-
$(D :) $(GLINK2 type, Type)
365-
366-
$(GNAME TemplateTypeParameterDefault):
367-
$(D =) $(GLINK2 type, Type)
368-
)
369-
370-
$(H4 $(LNAME2 parameters_specialization, Specialization))
371-
372-
$(P Templates may be specialized for particular types of arguments
373-
by following the template parameter identifier with a : and the
374-
specialized type.
375-
For example:)
376-
377-
------
378-
template TFoo(T) { ... } // #1
379-
template TFoo(T : T[]) { ... } // #2
380-
template TFoo(T : char) { ... } // #3
381-
template TFoo(T, U, V) { ... } // #4
382-
383-
alias foo1 = TFoo!(int); // instantiates #1
384-
alias foo2 = TFoo!(double[]); // instantiates #2 with T being double
385-
alias foo3 = TFoo!(char); // instantiates #3
386-
alias fooe = TFoo!(char, int); // error, number of arguments mismatch
387-
alias foo4 = TFoo!(char, int, int); // instantiates #4
388-
------
389-
390-
$(P The template picked to instantiate is the one that is most specialized
391-
that fits the types of the $(I TemplateArgumentList).
392-
If the result is ambiguous, it is an error.
393-
)
394-
395395

396396
$(H3 $(LNAME2 template_this_parameter, This Parameters))
397397

0 commit comments

Comments
 (0)