D struct are difficult to work with!

Hong Wing Hong_member at pathlink.com
Sun Mar 19 00:16:26 PST 2006


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;






More information about the Digitalmars-d-dtl mailing list