D struct are difficult to work with!
Hasan Aljudy
hasan.aljudy at gmail.com
Sun Mar 19 10:33:55 PST 2006
Hong Wing wrote:
> I found D structs to be harder to work with than C++ ones, for example, with
> array i can directly modify a struct by
>
> array[i].x = 9;
>
> but when it is in a Vector, I need to copy it out, modify the copy, and copy
> back into the Vector.
>
> SomeStruct s = vector[i];
> s.x = 9;
> vector[i] = s;
>
> Using a pointer is very inconvenient, especially for math structs, I can see
> things like
>
> *result = (*a + *b) * (*c)
>
> Would it be nice to extend "inout" to function return, so to have Vector opIndex
> with the following signature for structs:
>
> inout value_type opIndex(index_type index)
>
> This helps to make containers more transparent with native array, and much nicer
> to work with. And extend it to variables:
>
> inout SomeStruct s = vector[i];
> s.x = 9;
>
>
>
is there a particular problem with using a class rather than a struct?
More information about the Digitalmars-d-dtl
mailing list