static foreach issues

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 5 22:23:47 PDT 2017


On 09/05/2017 07:05 PM, Psychological Cleanup wrote:
 > Nesting static foreach and using enum has latent problem.
 >
 > static foreach()
 >   static foreach()
 >   {
 >      enum A = ;
 >   }
 >
 > compiler complains because A is defined multiple times by the outer most
 > foreach.

That's understandable as there are multiple As dropped into code.

 > To fix this
 >
 > static foreach()
 >   static foreach()
 >   {
 >      {
 >         enum A = ;
 >      }
 >   }
 >
 > But then compiler complains about unexpected { if in a scope where
 > normal {}'s are not expected.

Can you demonstrate with compilable code? Doing what you describe works 
for me:

void main() {
     static foreach(i; 0 .. 3)
         static foreach(j; 0 .. 3)
         {
             {
                 enum A = i * j;
             }
         }
}

Ali



More information about the Digitalmars-d mailing list