Today I've made an abortive attempt at replacing my code's [1] dependence on unstd.multidimarray [2] with ndslice. I'm guessing it's just me being stupid, but could anyone supply with some hints on how to do the conversion with a minimum of fuss?

Basically I have an N-dimensional array (N is known at compile time) of type T wrapped in a struct to carry some additional information. I then address it using size_t[N] fixed-size arrays, and loop over it a lot with foreach, which also uses size_t[N] as index.

So it looks something like this:

struct Field(T, uint N) {

  alias arr this;

MultidimArray!(T, N) arr; // is there any way to supply the correct type here with ndslice? I cannot use auto, right?

  this (in size_t[N] lengths) {
    arr = multidimArray!T(lengths);
  }
}
and then things like

foreach(immutable p, ref pop; someField) {
  pop = foo(someOtherField[bar(p)]);
  ...
}

where p is of type size_t[N].

I tried using ndarray in conjunction with the std.experimental.allocator, but I don't particularly care about memory management; these are large arrays that are allocated once and kept around for the duration of the program.

Any help would be appreciated.

[1] https://github.com/SFrijters/DLBC
[2] https://bitbucket.org/SFrijters/unstandard

Reply via email to