On Thursday, 9 January 2014 at 13:32:08 UTC, Dicebot wrote:
On Thursday, 9 January 2014 at 12:19:25 UTC, Frustrated wrote:
I guess I see what is going on. Since Array is a struct, a local copy is made and that never ends up updating the original?

How can I use it then like an object so this is not a problem?

returning by ref may do what you want:

@property std.container.Array!int arr() { return _arr; }
->
@property ref std.container.Array!int arr() { return _arr; }

As dicebot says, however, the issue is a bit more subtle.

An `Array` is actually little more than a pointer to a payload. Passing by value is "almost" free, and updating a copy *should* update the original...

...that is, if it wasn't for the "Gotcha" that the `Array` needs to be initialized first.

But overall, by ref should be just fine.

Reply via email to