www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Associative arrays, multithreading, Rebindable

reply "Jack Applegame" <japplegame gmail.com> writes:
If I want to pass a dynamic array from one thread to another, 
then I use immutable(T)[] and it is safe.
But what if I need to pass an associative array? I suppose that 
the use of immutable(T)[U] is unsafe. Because one thread can 
delete the entry and this will have an impact also on the 
instance of the array in another thread.
So I have to use immutable(T[U]). But the immutability of the 
entire array makes the array reference immutable too:

immutable int[string] foo;
foo = assumeUnique(other); // error

For immutable classes we can use std.typecons.Rebindable:

Rebindable!(immutable Foo) foo;
foo = new immutable Foo; // fine

But for immutable associative arrays we can't:

Rebindable!(immutable int[string]) foo; // error
foo = assumeUnique(other);

Error: template instance 
std.typecons.Rebindable!(immutable(int[string])) does not match 
template declaration Rebindable(T) if (is(T == class) || is(T == 
interface) || isArray!T)

Should Rebindable to support associative arrays?
Apr 12 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Jack Applegame:

 Should Rebindable to support associative arrays?
I guess so. But how to implement it? Bye, bearophile
Apr 12 2014
next sibling parent "Jack Applegame" <japplegame gmail.com> writes:
On Saturday, 12 April 2014 at 09:18:12 UTC, bearophile wrote:
 Jack Applegame:

 Should Rebindable to support associative arrays?
I guess so. But how to implement it? Bye, bearophile
May be just like Rebindable for classes?
Apr 12 2014
prev sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Saturday, 12 April 2014 at 09:18:12 UTC, bearophile wrote:
 Jack Applegame:

 Should Rebindable to support associative arrays?
I guess so. But how to implement it? Bye, bearophile
Related: "Rebindable supports arrays (Which makes no sense)" https://issues.dlang.org/show_bug.cgi?id=12046 Quote: "It *might* make sense with associative arrays though... Not sure"
Apr 12 2014