aa.keys, synchronized and shared

Kagamin spam at here.lot
Fri Nov 11 14:19:31 UTC 2022


Try this:
```
synchronized final class SyncAA(K, V)
{
	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;
	ref inout(V[K]) unsharedTable() inout
	{
		return *cast(inout(V[K])*)&sharedTable;
	}
}
void f(shared SyncAA!(string,string) a)
{
	a.keys();
	a["12"]="34";
	a.remove("12");
}
```


More information about the Digitalmars-d-learn mailing list