Alternative solutions to returning ref types.

kede dev at null.com
Sat Mar 15 02:38:52 PDT 2008


Hi...

I'm still having a great time using D for graphics programming at the moment.
However, I'm constantly irritated by my initial design decision to implement the lower level objects as structs simply because it has led do (a now ridiculous amount) of code along the lines of the following:

model.origin = model.origin + vec3(0,1,0);
 -- or --
o = model.origin;
o.y += 1;
model.orgin = o;

When all I really want is just:   model.origin.y++;
Worse still, model.origin.y++ is legal but doesn't do what you would expect.

I'm sure most of you have this problem to some degree or another.  However, it doesn't look like returnable ref types are going to be implemented in D any time soon, so I want to ask you guys what you are currently doing to deal with this.

For the sake of discussion take a 3d vector object as an example.
Given that it is small in size, frequently allocated and deallocated, commonly used inside other class objects.

The obvious solutions are:
1. Use a pointer to return it.  -- urgh
2. Implement it as a class.
3. As 2 with custom 'new' 'delete'


Thanks in advance for any ideas you might have...

Have fun,
k




More information about the Digitalmars-d mailing list