aa.keys, synchronized and shared
Kagamin
spam at here.lot
Mon Nov 14 07:57:16 UTC 2022
This works for me:
```
synchronized final class SyncAA(K, V)
{
this(K key, V val) { sharedTable[key]=val; }
V opIndex(K key) { return sharedTable[key]; }
V opIndexAssign(V value, K key) { return sharedTable[key]=value;
}
const(K[]) keys() const { return unsharedTable.keys; }
void remove(K key) { sharedTable.remove(key); }
V get(K key, lazy V defaultValue=V.init)
{
auto p = key in sharedTable;
return p ? *p : defaultValue;
}
private:
V[K] sharedTable;
inout(V[K]) unsharedTable() inout
{
return cast(inout(V[K]))sharedTable;
}
}
shared SyncAA!(string,string) saa;
void f()
{
saa=new shared SyncAA!(string,string)("1","2");
saa.keys();
saa["12"]="34";
saa.remove("12");
}
```
More information about the Digitalmars-d-learn
mailing list