How to define templates

Steve Teale steve.teale at britseyeview.com
Sun Mar 29 12:01:30 PDT 2009


Jarrett Billingsley Wrote:

> On Sun, Mar 29, 2009 at 2:28 PM, Steve Teale
> <steve.teale at britseyeview.com> wrote:
> >
> > 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.
> 
> Because... templates don't contain statements?  I'm not sure what your
> question is, or what not using T, U, and V have to do with it.
> 
> > 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.
> 
> Same idea as function arguments or locals.  Just a QOI issue.
> 
> > What is the basic difference between Templates and Macros - the declarations thing is obviously crucial, but why?
> 
> That can't really be answered until macros make their way into the
> language ;)  but templates parametrize declarations, whereas macros
> parametrize arbitrary code.  A parametrized type is something very
> different from arbitrary code.

That's a most useful answer, and some of it should be in the documentation. I had tended to think that templates were something more general that macros. Maybe that's why (like many others) I've never really understood them.

It also accounts for most of the error messages I've got when trying to use templates.

So will we get macros ;=) ?




More information about the Digitalmars-d mailing list