On 2/22/20 2:29 PM, Robert M. Münch wrote:
I don't get how I can create a dynamic array of Cycle buffers of size 2 which use a struct.

  struct ms {
    int a;
    int b;
  }
  ms[2] msBuffer;
  alias circularStructBuffersT = typeof(cycle(msBuffer));
  circularStructBuffersT[int] circularStructBuffers;

  int i = 2;
  auto x = circularStructBuffers.require(i, (){
    ms[2] t;
    return cycle(t,2);
  });

It looks like require() requires :) a value, which it evaluates only if necessary:

  https://dlang.org/spec/hash-map.html#inserting_if_not_present

In your case, you're passing a callable. All you need to do is to actually call that callable with empty parenthesis:

  auto x = circularStructBuffers.require(i, {
    // ...
    }());  // <-- HERE

Because the parameter is lazy, it will still be called only when needed.

Ali

Reply via email to