I was reading "D Templates: A Tutorial" by Philippe Sigaud which says:

--------------------------- quote
What is a Template? In the next chapters, you’ll see how to define function, struct and class templates.

But before that, I’d like to introduce what a template really is, because this definition is the most fundamental of the whole document. As I said, a template is a way to define a blueprint to generate some code, be it a class definition, a function or. . . what? What could be the most abstract unit of code?

But where is the basic unit to hold this code? Well, a code block of course, or a
scope.

This is what a template is, at its core: a named, parameterized,
code block, ready to be instantiated just for you.
--------------------------- end quote


so thinking that I had reached a first principle, I wrote the above template. But then when this failed to compile, I then read further and it says:


--------------------------- quote
Template Declarations

Here is the syntax for a template declaration:

template templateName(list, of, parameters)
{
    // Some syntactically correct declarations here
    // The arguments are accessible inside the template scope.
}
--------------------------- end quote

so the code block must consist only of declarations. Which lead to me to ask my original question.

mixins could work but I'm just trying to understand templates and this particular limitation.

Reply via email to