Calls to struct methods and immutable

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Wed Dec 5 07:22:58 PST 2012


On 11/30/2012 05:45 AM, Ali Çehreli wrote:
> I've forced it pretty hard: :D
>
>      immutable(Network) idup() pure const @property
>      {
>          Node[uint] nodesCopy;
>
>          foreach (key, node; nodes) {
>              immutable(Node) nodeCopy = node.idup;
>              nodesCopy[key] = cast(Node)nodeCopy;
>          }
>
>          immutable imnodes = assumeUnique(nodesCopy);
>          return immutable(Network)(imnodes);
>      }
>
> I hope it is safe. :p

You know, now I'm embarrassed, because I really should have come up with this 
myself. :-P

Actually, I think I did, but I was concerned that the returned result wouldn't 
actually be identical to the original, inasmuch as e.g. inserting the nodes one 
by one might cause everything to be in a different order to the original.  So I 
didn't have the confidence to try it out.

Of course, I could always test these things ...

Thanks very much for the suggestion!


More information about the Digitalmars-d-learn mailing list