www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.typecons.Rebindable

reply "Jack Applegame" <japplegame gmail.com> writes:
Why doesn't Rebindable allow associative arrays?

import std.typecons;

Rebindable!(immutable string[]) data1;       // ok
Rebindable!(immutable string[string]) data2; // error
Jan 31 2014
parent reply "Frustrated" <c1514843 drdrb.com> writes:
On Friday, 31 January 2014 at 08:40:30 UTC, Jack Applegame wrote:
 Why doesn't Rebindable allow associative arrays?

 import std.typecons;

 Rebindable!(immutable string[]) data1;       // ok
 Rebindable!(immutable string[string]) data2; // error
an associative array doesn't pass the isArray test isArray!(string[]) // true isArray!(string[string]) // false Not sure if there is some inherent reason why but I would venture to say it is a bug.
Jan 31 2014
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Friday, 31 January 2014 at 12:43:21 UTC, Frustrated wrote:
 On Friday, 31 January 2014 at 08:40:30 UTC, Jack Applegame 
 wrote:
 Why doesn't Rebindable allow associative arrays?

 import std.typecons;

 Rebindable!(immutable string[]) data1;       // ok
 Rebindable!(immutable string[string]) data2; // error
an associative array doesn't pass the isArray test isArray!(string[]) // true isArray!(string[string]) // false Not sure if there is some inherent reason why but I would venture to say it is a bug.
What's the point of using Rebindable for a non-[class|interface] type? They are the only type where it makes sense, since you can't give different qualifiers to the handler and the object. I'm surprised it even handles arrays at all. As a matter of fact, the documentation says: "However, Rebindable!(T) does not compile if T is a non-class type." If arrays worked, I think it was buggy behavior. There's no sense in having a Rebindable array.
Jan 31 2014
parent "Jack Applegame" <japplegame gmail.com> writes:
 What's the point of using Rebindable for a non-[class|interface]
 type? They are the only type where it makes sense, since you
 can't give different qualifiers to the handler and the object.

 I'm surprised it even handles arrays at all. As a matter of 
 fact,
 the documentation says:
 "However, Rebindable!(T) does not compile if T is a non-class
 type."
 If arrays worked, I think it was buggy behavior. There's no 
 sense
 in having a Rebindable array.
Hmm. I need to pass an unique associative array to several threads. If this array has immutable elements, but isn't immutable itself, then what happen if one of threads adds or removes element from array? Associative arrays is some kind of hash-table. Adding alements in one thread can cause undefined behaviour in other thread. Am I wrong?
Feb 02 2014