Structure of Arrays vs Array of Structures

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 15 12:52:03 PDT 2017


On Monday, 15 May 2017 at 17:10:49 UTC, Per Nordlöw wrote:
> On Monday, 15 May 2017 at 07:31:25 UTC, Nordlöw wrote:
>> On Monday, 15 May 2017 at 06:50:04 UTC, Nicholas Wilson wrote:
>>> Yes, https://maikklein.github.io/post/soa-d/
>>
>> Ok, great. Thanks.
>>
>> I can't seem to find any Github code repo, tough. Does it 
>> exist?
>
> Here's my fixed version of soa-d that doesn't use Tuple and 
> therefore compiles and links 3 times as fast.
>
> https://github.com/nordlow/phobos-next/blob/master/src/soa.d

I'm trying to implement reference access via for instance

     T.init[0].i

given that

     struct S { int i, float f; }
     alias T = SOA!S;

by adding

     /// Reference to element in `soaPtr` at index `elementIndex`.
     private struct ElementRef
     {
         SOA* soaPtr;
         size_t elementIndex;
         auto ref opDispatch(string name)()
             @trusted return scope
         {
             return (*soaPtr).name[elementIndex];
         }
     }

but when I also define

     ref inout(ElementRef) opIndex(size_t elementIndex) inout 
return scope
     {
         return ElementRef(this, elementIndex);
     }

the compilation errors as

soa.d-mixin-143(143,7): Error: variable 
soa.SOA!(S).SOA.container0LU cannot be further field because it 
will change the determined SOA size
soa.d-mixin-143(143,28): Error: variable 
soa.SOA!(S).SOA.container1LU cannot be further field because it 
will change the determined SOA size
soa.d(193,14): Error: template instance soa.SOA!(S) error 
instantiating
soa.d(195,5): Error: static assert  (is(typeof((__error)()) == 
int[])) is false

What's wrong?


More information about the Digitalmars-d-learn mailing list