structs, templates, alias

Ellery Newcomer ellery-newcomer at utulsa.edu
Sun Apr 25 11:15:49 PDT 2010


On 04/25/2010 12:26 PM, Robert Clipsham wrote:
> On 25/04/10 16:04, Ellery Newcomer wrote:
>> Does anyone have any ideas regarding this problem?
>
> I haven't looked into this fully, but for the "the length field and the
> array/structure are separated by one or more fields" issue, something
> like this should help:
> ----
> foreach( m; MyStruct.tupleof )
> {
> static if( is( typeof(m) x : x[] ) )
> {
> // This member is an array, so read the size_t length first, then
> // the elements
> }
> else
> {
> // Treat normally.
> }
> }
> ----

Yeah, that's about what I do. The trouble is getting blit to know which 
field is the length field. I suppose you could pass an index into the 
tuple to the substructure. That still wouldn't fix the substructure 
being able to modify the field length.

>
> I don't think there's a way of finding if a member is part of an
> anonymous union, the only way around this seems to be to use a named
> union so it is treated as one field.

Well, I assume anything with a union has to be special cased anyways, 
especially when the union has fields of different sizes. Everything's 
always written little endian, and I suspect treating the union as a 
single field would cause problems on mac, etc.


More information about the Digitalmars-d-learn mailing list