Jump to content

[SOLVED] Nested foreachkey bug


photo

Recommended Posts

Posted

Problem

 

There seems to be a bug with nested foreachkey language constructs. The following code

  	Statistics map[];

  	foreachkey( string row; map )
   	{
    	...
       	foreachkey( string column; map )	// ERROR
       	{
          	....
       	}
   	}

 

produces "UserArray::forEachKeyStep(): bad map iterator" error message.

 

 

Workaround

 

Usage of redundant map copy for inner foreachkey loop works

  	Statistics map[];
  	Statistics map_copy[];

  	map_copy.copy( map );

  	foreachkey( string row; map )
  	{
    	...
       	foreachkey( string column; map_copy )	// NO ERROR
       	{
          	....
       	}
   	}

Posted

It's not a bug, it's a feature.

bug-vs-feature.jpg

 

The iterator is stored inside the array because of performance reason.

Posted

ok, than some hint/warning within documentation an foreachkey would be helpful

×
×
  • Create New...