SOA

Implement Struct Of Arrays from a struct type and array size.

Inspired by code at https://github.com/economicmodeling/soa/blob/master/soa.d

// Transforms a struct definition like this
struct Vector2 {
  float x = 0;
  float y = 0;
}
Vector2[100] arrayOfStructs;

// To a struct definition like this
struct Vector2_SOA {
  float[100] x = 0;
  float[100] y = 0;
}
// alias Vector2_SOA = SOA!(Vector2, 100);
Vector2_SOA structOfArrays;

Provides a dispatching object for member access, comparison, assignment and others, and also provides a Random Access Finite Range of those, allowing seamless substitution of Array Of Structs and Struct Of Arrays types.

SOA!(Vector2, 100) vectors;
vectors[0].x = 10;
assert(vectors[0].x == 10);
assert(vectors[0].x == vectors.x[0]);
vectors[1] = Vector2(2, 2);
assert(vectors[1] == Vector2(2, 2));

foreach(v; vectors[0 .. 2])
{
    import std.stdio;
    writeln(v.x, " ", v.y);
}

Constructors

this
this(R range)

Construct SOA with initial elements copied from range.

Members

Aliases

Dispatcher
alias Dispatcher = .Dispatcher!(T, N)
Undocumented in source.
DispatcherRange
alias DispatcherRange = .DispatcherRange!(T, N)
Undocumented in source.
ElementType
alias ElementType = T
Undocumented in source.
opDollar
alias opDollar = length
Undocumented in source.

Functions

opIndex
inout(Dispatcher) opIndex(size_t index)

Returns a Dispatcher object to the pseudo-indexed T instance.

opIndex
inout(DispatcherRange) opIndex()

Returns the full range of Dispatcher objects.

opOpAssign
void opOpAssign(T value)

Concatenate a value.

opOpAssign
void opOpAssign(R range)

Concatenate values from range.

opOpAssign
void opOpAssign(Dispatcher!(T, M) dispatcher)

Concatenate a value from Dispatcher.

opSlice
inout(DispatcherRange) opSlice(size_t beginIndex, size_t pastTheEndIndex)

Returns a range of Dispatcher objects.

Manifest constants

length
enum length;

Length of the arrays.

Properties

length
size_t length [@property getter]

Length of the arrays, assumed to be the same between all of them.

Variables

firstLength
size_t firstLength;
Undocumented in source.

Meta