Calls to struct methods and immutable
Ali Çehreli
acehreli at yahoo.com
Thu Nov 29 20:45:12 PST 2012
On 11/27/2012 06:05 AM, Joseph Rushton Wakeling wrote:
> On 11/27/2012 01:16 PM, Joseph Rushton Wakeling wrote:
>> immutable(Node) idup() pure const @property
>> {
>> auto linkCopy = to!(Link[])(links);
>> immutable ilinks = assumeUnique(linkCopy);
>> return immutable(Node)(id, ilinks);
>> }
>
> Actually I'm being overly complicated here as with dynamic arrays I can
> simply do,
>
> immutable(Node) idup() pure const @property
> {
> return immutable(Node)(id, links.idup);
> }
>
> ... so the real issue here seems to be that there's no canonical way
> (that I can find) to idup an _associative_ array.
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
Ali
More information about the Digitalmars-d-learn
mailing list