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 through fields in this way doesn't modify the object
auto fields = ret.tupleof;
foreach(ref field; fields) {
field = 1; // this doesn't alter 'ret'
}
// WORK
foreach(ref field; ret.tupleof) {
field = 1; // this does alter it!!!
}
return *ret;
}
(Of course the real code doesn't use the value '1'. It uses
values from an ubyte[] with the corresponding types of T's fields)
Can somebody explain me why it is work like that?
Thanks a lot.