turning an array of structs into a struct of arrays
Babu via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 3 04:00:59 PDT 2015
On Friday, 3 July 2015 at 10:52:03 UTC, Laeeth Isharc wrote:
> 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.
see https://github.com/economicmodeling/soa
More information about the Digitalmars-d-learn
mailing list