How can this best be done?
Johan Fjeldtvedt
jaffe1 at gmail.com
Mon Oct 14 16:48:26 PDT 2013
This post concerns the following code:
https://gist.github.com/Jaffe-/6983847
It is an attempt to abstract away the details of storing a
collection of struct elements as so-called parallel arrays
(http://en.wikipedia.org/wiki/Parallel_array) instead of storing
them sequentially.
The ParallelArray template takes a struct, S, and a number of
elements, SIZE, and creates a struct where each field is an array
of size SIZE, for each field of S. The struct overloads opIndex,
opIndexAssign and opApply, so that it can be used just like an
ordinary array of structs.
It's pretty neat and works fine, but I feel it's somewhat hacky.
Is it okay to use .tupleof the way I do here? It does work, but I
can't say I understand exactly how. Also, the recursive template
bugs me. Can the code which declares the struct members be
generated in some better way? I've tried writing a CTFE-able
function to build the string instead of doing it recursively in
the template, but I haven't been able to do it yet.
More information about the Digitalmars-d-learn
mailing list