ref fields of .tupleof

Ali Çehreli acehreli at yahoo.com
Tue May 29 15:11:15 PDT 2012


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(ref field; fields) {
 > field = 1; // this doesn't alter 'ret'
 > }

Ali



More information about the Digitalmars-d-learn mailing list