Foreach on a template?

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Mar 11 15:35:33 PDT 2007


"Robin Allen" <r.a3 at ntlworld.com> wrote in message 
news:et1cch$2gmi$1 at digitalmars.com...
> Okay, I should have said they *should* mean the same thing. Or that the 
> programmer using foreach would *mean* the same thing. Anyway, acording to 
> the spec, foreach expects an 'expression' which can be pretty much 
> anything, so there's no reason why a template shouldn't work.

Just because it expects an expression doesn't mean it should be able to 
handle *any* expression.  What about

foreach(x; 5)

?  That makes no sense.

The grammar of foreach just defines what can come there syntactically.  It's 
the semantics that determine what's _legal_ there. 





More information about the Digitalmars-d mailing list