D struct are difficult to work with!

Derek Parnell derek at psych.ward
Sun Mar 19 16:12:51 PST 2006


On Sun, 19 Mar 2006 08:16:26 +0000 (UTC), 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;

I'm sorry but I don't know what you are meaning by 'vector' in this
context? Do you mean a reference to an array of structs? Can you show me
some real code that demonstrates the issue for you. 

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
20/03/2006 11:08:55 AM



More information about the Digitalmars-d-dtl mailing list