How to define templates
Steve Teale
steve.teale at britseyeview.com
Sun Mar 29 11:28:26 PDT 2009
Jarrett Billingsley Wrote:
> On Sun, Mar 29, 2009 at 1:46 PM, Steve Teale
> <steve.teale at britseyeview.com> wrote:
> > The documentation says:
> >
> > TemplateDeclaration:
> > template TemplateIdentifier ( TemplateParameterList ) Constraint(opt)
> > { DeclDefs }
> >
> > DeclDefs as defined where?
>
> http://www.digitalmars.com/d/2.0/module.html
>
> > What should be the effect of the following?
> >
> > import std.stdio;
> >
> > template gnomeSaying(T, U, V, string s)
> > {
> > writefln(s ~ " motherfucker");
> > }
>
> An error, since a function call is not a DeclDef.
OK, I didn't look there - perhaps a definition in 'Decalrations' would make thing easier.
But then I wonder, since a plain old string is acceptable as a template parameter, why I can't use a statement that does not involve any of the other template arguments.
Also, would it be reasonable for the compiler to issue a warning or error message to the effect that T, U, and V were never mentioned in the template body.
What is the basic difference between Templates and Macros - the declarations thing is obviously crucial, but why?
More information about the Digitalmars-d
mailing list