turning an array of structs into a struct of arrays

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 3 03:52:02 PDT 2015


I have an array of structs eg

struct PriceBar
{
   DateTime date;
   double open;
   double high;
   double low;
   double close;
}

(which fields are present in this particular struct will depend 
on template arguments).

what is the best way to turn these at compile time into a struct 
of arrays? eg

struct PriceBars
{
   DateTime[] dates;
   double[] opens;
   double[] highs;
   double[] lows;
   double[] closes;
}

I can use FieldTypeTuple and FieldNameTuple, but I am a bit lost 
as to how without static foreach to loop through these in order 
to generate a mixin to declare the new type.  I can turn it into 
a string, but what is the better option?

Thanks.


More information about the Digitalmars-d-learn mailing list