TMapEnumerator
BlitzMax Forums/BlitzMax Programming/TMapEnumerator
| ||
I'm not posting this as a bug, but something to look out for. Storing the enumerator from a TMap in a temp variable and iterating through it destroys its contents, so you can only do it once. It tripped me up! (Of course getting it from map.values() again is ok)Strict
Local map:TMap = New TMap
map.insert("key1", "value1")
map.Insert("key2", "value2")
map.insert("key3", "value3")
Local mvalues:TMapEnumerator = map.values()
Print "map"
For Local v:String = EachIn mvalues
Print v
Next
Print "map"
For Local v:String = EachIn mvalues
Print v
Nextmap value1 value2 value3 map |
| ||
it's not receting the enumarator that is all.
Strict
Local map:TMap = New TMap
map.insert("key1", "value1")
map.Insert("key2", "value2")
map.insert("key3", "value3")
Local mvalues:TMapEnumerator = map.values()
Print "map"
For Local v:String = EachIn mvalues
Print v
Next
mvalues=map.values()
Print "map"
For Local v:String = EachIn mvalues
Print v
Next
|
| ||
| why would you want to keep the enumerator object? |
| ||
| I'm curious about this now. What're you doing that requires you to keep a reference to the enumerator? |
| ||
| Thats by default what an Enumerator should do, iterating from begin to the end of a List, Map etc. - if it reaches the end, it is still at the end of the list. But I'm just as curious as Nilium :) |
| ||
| I just wanted to iterate through the same map twice in a row is all :) |
| ||
Then you have to do it like jesse wrote or:
Strict
Local map:TMap = New TMap
map.insert("key1", "value1")
map.Insert("key2", "value2")
map.insert("key3", "value3")
For Local v:String = EachIn map.values()
Print v
Next
mvalues=map.values()
Print "map"
For Local v:String = EachIn map.values()
Print v
Next
|
| ||
| Erm, this is quite odd behaviour. In other languages an Enum is a const, and it doesnt 'disappear' after use, and you dont need to re-evaluate it. This does sound like a garbage collect bug or there must be a better way to define an Enum type object. Last edited 2011 |
| ||
| In other languages an Enum is a const, and it doesnt 'disappear' after use, and you dont need to re-evaluate it. It's not an Enum (like in C) it's an map enumerator, a class used to enumerate (or step) through items in a TMap. Last edited 2011 |