Re: ref semantics with hashes

2012-05-07 Thread Steven Schveighoffer
On Sat, 05 May 2012 00:11:04 -0400, Kagamin wrote: Well, if one needs strictly ref dictionary class Dictionary(TKey, TValue) { TValue[TKey] dictionary; alias dictionary this; } This is a wasted memory block. dictionary already has reference semantics *as long as* it has been initiali

Re: ref semantics with hashes

2012-05-04 Thread Kagamin
Well, if one needs strictly ref dictionary class Dictionary(TKey, TValue) { TValue[TKey] dictionary; alias dictionary this; }

Re: ref semantics with hashes

2012-05-03 Thread Andrej Mitrovic
On 5/3/12, Artur Skawina wrote: >alias p1.p2.p3.p4.p5.p6.hash hash3; >alias p1.p2?p1.p2.hash:p3.p4.hash hash4; >alias getfoo().hash hash5; I was under the impression that alias would only be used as a compile-time alias to a nested symbol. So this: alias p1.p2.p3.hash foo; test(foo);

Re: ref semantics with hashes

2012-05-03 Thread Steven Schveighoffer
On Wed, 02 May 2012 16:32:04 -0400, H. S. Teoh wrote: On Wed, May 02, 2012 at 09:38:35PM +0200, Andrej Mitrovic wrote: [...] So if the hash wasn't already initialized then the reference in the Foo struct is a reference to null, and if you duplicate that reference and add a key the old refere

Re: ref semantics with hashes

2012-05-03 Thread Artur Skawina
On 05/03/12 00:38, Andrej Mitrovic wrote: > In fact what would *actually* solve this problem (for me) is if/when > we have aliases implemented for this scenario: > > import std.stdio; > > struct Foo > { >int[] hash; > } > > void main() > { > Foo foo; > alias foo.hash hash2; > >

Re: ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
On 5/3/12, Andrej Mitrovic wrote: > import std.stdio; > > struct Foo > { >int[] hash; > } Sorry that should have been int[int] there.

Re: ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
On 5/2/12, Jonathan M Davis wrote: > The way that AAs work in this regard is identical to how dynamic arrays > work. Yes but they're very different in other regards. For example, if you add an element to one array it doesn't automatically add an element to the other array: int[] a = new int[

Re: ref semantics with hashes

2012-05-02 Thread bearophile
H. S. Teoh: I was told that this was expected behaviour. It's trash behavior, bug-prone and not intuitive. It has the worst qualities of both a struct and a class :-) Should the new AA implementation change this, so that it always allocates an empty AA upon instantiation? Sounds like a po

Re: ref semantics with hashes

2012-05-02 Thread Jonathan M Davis
On Wednesday, May 02, 2012 13:32:04 H. S. Teoh wrote: > On Wed, May 02, 2012 at 09:38:35PM +0200, Andrej Mitrovic wrote: > [...] > > > So if the hash wasn't already initialized then the reference in the > > Foo struct is a reference to null, and if you duplicate that reference > > and add a key th

Re: ref semantics with hashes

2012-05-02 Thread H. S. Teoh
On Wed, May 02, 2012 at 09:38:35PM +0200, Andrej Mitrovic wrote: [...] > So if the hash wasn't already initialized then the reference in the > Foo struct is a reference to null, and if you duplicate that reference > and add a key the old reference still points to null. > > The only way to ensure a

ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
import std.stdio; struct Foo { int[int] hash; } void main() { test1(); test2(); } void test1() { Foo foo; foo.hash[1] = 1; auto hash2 = foo.hash; hash2[2] = 2; writeln(foo.hash); // [1:1, 2:2] writeln(hash2); // [1:1, 2:2] } void test2() { Foo foo;