> If they're evaluated at the instantiation scope, and not in the point of
> definition, then why are statements disallowed?
> 
> Where does the limitation come from?

Probably because statements are only valid in functions, and a template is a 
set of declarations. It certainly wouldn't make any sense to have a normal 
template include statements, and the whole template mixin thing grew out of 
normal templates, so even if it makes perfect sense for template mixins to 
include statements, since they came out of normal templates in the first place 
(which can't have statements, since it would make no sense), they wouldn't 
wouldn't be able to have statements unless Walter thought to add that 
capabality specifically with mixing in in mind.

But while templates that you mixin are generally designed for that and 
therefore designed differently than normal templates, I don't believe that 
there's any really difference in them except in how you instantiate them, so 
the compiler is going to end up treating them the same as far as the lexer and 
parser go. And since it makes no sense for normal templates to have 
statements, templates that you mixin don't either. But think of the mess that 
you'd have if you tried to instantiate a template as a normal template when it 
held statements? You'd probably get some pretty weird errors if that were 
allowed.

So, I think that the limitation comes primarily from the fact that prior to 
mixins it made no sense for templates to contain naked statements, and 
templates intended for being used in mixins aren't really any different from 
normal templates from the compiler's perspective.

- Jonathan M Davis

Reply via email to