various questions

Jason Spencer spencer8 at sbcglobal.net
Fri Jul 30 00:44:51 PDT 2010


== Quote from Rory Mcguire (rjmcguire at gm_no_ail.com)'s article
> Jason Spencer wrote:

> > I nievely went and replaced "foreach (t; Iota!(str_types.length))"
> > with "foreach (t; str_types.length)", since the length of that
> > array is known at compile-time.

> your replacement tries to loop over an uint called str_types.length.
> Never gonna happen.
> Iota!(str_types.length) seems to generate str_types.length(a number
> of)integer indexes. Can't use 0 .. str_types.length in the foreach
> because compiler is expecting Integer constants so it can make the
> template "foo" into actual code.

Not quite sure I follow.  I think you're saying the range in foreach
has to be actual literals, and not just an expression that can be
evaluated at compile time to generate the same range...close?

If that's the case, then why does it work to instantiate Iota! with
str_types.length?  It can obviously get the value behind it at compile
time.  I'm still missing something.

Jason



More information about the Digitalmars-d-learn mailing list