C++ reference type
Tesuji
Tesuji_member at pathlink.com
Sun Jun 25 01:32:44 PDT 2006
Sounds like you have quite a lot of experience working around the lack of C++
reference type. I just wonder if it will ever be included in D?
>Not to pick but you could say:
>
>auto x = arr4[0];
>x.bar = 100;
>
>or you could simply use a different method:
>
>class Array(T)
>{
> T[] items;
>...
> T* ptr(int n=0) { return items.ptr + n ; }
>}
>
>arr.ptr[5].bar = 1;
>
>Since the built int arrays use a .ptr property, I usually define this
>method anyways. Once you use it for a while its second nature.
>
>If you need to change a lot of entries, use foreach which returns an
>inout reference.
>
>If you want to get crazy:
>
> void opIndexAssign( void delegate(T* item) fn, int n )
> {
> fn( items.ptr + n );
> }
>
>
>then:
>arr[0] = (Foo* f){f.bar += 3;};
>
>hehe :P
>
>Seriously though, if the item is small enough to not warrant a class,
>then just extend the container class and define a custom method to
>update the item.
>
>-DavidM
>
More information about the Digitalmars-d
mailing list