Re: ref fields of .tupleof

2012-05-29 Thread Jacob Carlborg
On 2012-05-29 21:18, Sharp wrote: Hi all! I've spend several hours to solve my problem, and I did it! But don't know why it is worked in this way: I'd like to modify all fields of an object by a specific values (for deserialization). If you want a serialization library: https://github.com/ja

Re: ref fields of .tupleof

2012-05-29 Thread Sharp
Thanks a lot Ali, I understand now! Philippe, based on what Ali said, your code will give exactly the same result because it looping through a local copy of ret.tupleof.

Re: ref fields of .tupleof

2012-05-29 Thread Ali Çehreli
On 05/29/2012 12:18 PM, Sharp wrote: > public ref T foo(T)() { > T *ret = new T; > // DON'T WORK > // Looping through fields in this way doesn't modify the object > auto fields = ret.tupleof; Looks like fields is a local copy of ret.tupleof so the following modifies just that copy. > foreach(

Re: ref fields of .tupleof

2012-05-29 Thread Philippe Sigaud
On Tue, May 29, 2012 at 9:18 PM, Sharp wrote: What does it give if you do: >        foreach(index, unused; fields) { >                fields[index] = 1; >} ?

ref fields of .tupleof

2012-05-29 Thread Sharp
Hi all! I've spend several hours to solve my problem, and I did it! But don't know why it is worked in this way: I'd like to modify all fields of an object by a specific values (for deserialization). public ref T foo(T)() { T *ret = new T; // DON'T WORK // Looping thro