4 ms·
The opposite of "struct" isn't "enum", it's "union" (or "variant"). This blog post isn't about turning an array of enums into an "enum of arrays"; it's about tu
by quuxplusone 2y ago
The opposite of "struct" isn't "enum", it's "union" (or "variant"). This blog post isn't about turning an array of enums into an "enum of arrays"; it's about turning an array of unions into a union of arrays.
Which breaks down if any of your unions hold different alternatives. The "array of structs to struct of arrays" transformation, OTOH, cannot break.
It's also common to transform an "array of unions" (or "array of [pointers to] polymorphic types") into a "struct of shorter [homogeneous] arrays."