various questions

Rory Mcguire rjmcguire at gm_no_ail.com
Fri Jul 30 01:20:11 PDT 2010


Jason Spencer wrote:

> == 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

I convert str_types.length to its actual value below:
foreach (t; 3) {
...
}

You can't do that (dmd : t.d(6): Error: int is not an aggregate type)





More information about the Digitalmars-d-learn mailing list