Enumerator do not points to allowable element

Hello All. Please see the code below, it being compiles but does not running (the error message is popped-up: “Enumerator do not points to allowable element” (translated from Russian)). I would appreciate if you can check it, and give a comment (or – the best scenario is to have a link to relevant information for studying). Thank you in advance, Oleksandr

{
/*
Define container of integer values:
[8, 16, 4, 70, -20, 14, 14, 3, 255, 45, 24, 100]
Convert it to the set of integers.
Remove all negative values from the set.
Output set using setEnumerator.

container con = [8, 16, 4, 70, -20, 14, 14, 3, 255, 45, 24, 100];
Set set;

{ */
Set is1;
int temp;
container contTemp;
SetEnumerator se;

container packedSet = [8, 16, 4, 70, -20, 14, 14, 3, 255, 45, 24, 100];

int len = conLen(packedSet);

is1 = Set::create([1, any2int(Types::Integer), len] + packedSet);//transfering of container to Set

se = is1.getEnumerator();

while(se.moveNext())
{
temp = se.current();

if(temp < 0)
{
is1.remove(temp);

}
info(strFmt("%1", temp));
}
}

I think you should use Set::create() only with containers created by Set.pack().

Even if you manage to construct a container mimicking a packed set, your code would depend on an undocumented behavior that can change without warning. Use Set.add() to add items to a set - that’s a supported, public interface.

Oh, now I see another problem in your code - you’re changing the collection you’re iterating. That’s a serious flaw.

Simply iterate the container in a for loop (you don’t need to convert it to Set) and if an item is >= 0, add it into a set. Simple and flawless.

Hello Martin,

Thank you for your help.

Oleksandr

Can you please mark the reply that answered your question as the verified solution?