ref semantics with hashes

Artur Skawina art.08.09 at gmail.com
Thu May 3 03:01:19 PDT 2012


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;
> 
>     hash2[0] = 1;
>     writeln(foo.hash);  // [1:1]
>     writeln(hash2);     // [1:1]
> }
> 
> Hopefully we get that one day.

Until then, you can use

   @property ref hash2() { return foo.hash; }

which is a bit more verbose, but functionally equivalent.
Your new alias syntax would be just sugar, and would (a) hide the
complexity of the operation and (b) have to be artificially restricted.

   alias p1.p2.p3.p4.p5.p6.hash hash3;
   alias p1.p2?p1.p2.hash:p3.p4.hash hash4;
   alias getfoo().hash hash5;   

etc would also be possible otherwise and that isn't necessarily a good
idea.

artur


More information about the Digitalmars-d-learn mailing list