"if" is not evaluated for fields of Class.tupleof

Timoses via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 19 06:46:15 PDT 2017


Hey there,

trying to read data into the fields of a class.

This is what I got so far:

```
import std.traits;
import std.bitmanip;

class Test {
     byte[4] marray;
     byte mbyte;

     this(ubyte[] data)
     {
         auto fields = this.tupleof;

         foreach (field; fields)
         {
             // Here it should actually not enter when field is 
mbyte (byte)
             if (isStaticArray!(typeof(field)))
             {
                 for (int i = 0; i < field.length; i++)
                     field[i] = data.read!(typeof(field[i]));
             }
             else
             {

             }
         }
     }
}

void main() {
     new Test([0x12, 0x23, 0x34, 0x45, 0x56]);
}
```

The problem is that `isStaticArray` won't halt when the field is 
`byte`.

When I add a `writeln(isStaticArray!(typeof(field)));` it will 
write `false` for `mbyte` though...

What's the problem? Is it a bug?

And: Is there a better way to do what I'm trying to do?...


More information about the Digitalmars-d-learn mailing list