roxen.lists.pike.general

Subject Author Date
Re: Iterators and deleting entries from mappings Martin Stjernholm <mast[at]lysator[dot]liu[dot]se> 15-01-2009
"Mirar @ Pike  importmöte för mailinglistan" <<6341[at]lyskom.lysator.liu.se>>
skrev:

> I had expected the mapping to get a copy-on-write flag and to loop
> over all the initial values. :p

Unfortunately it seems you're right. I'm sorry for the misinformation.
The behavior I described only applies to multisets; I thought mappings
were fixed to behave similarly.

The thing is that your wanted behavior is very easy to achieve by
doing the deferred copy explicitly:

   foreach (m + ([]); mixed ind; mixed val) {
     ..
   }

It's both simple and makes the code more obvious. But in cases where
an implicit deferred copy is unwanted overhead, it cannot be avoided
with the current mapping behavior.