mir: How to change iterator?

jmh530 john.michael.hall at gmail.com
Tue Apr 14 20:24:05 UTC 2020


In the code below, I multiply some slice by 5 and then check 
whether it equals another slice. This fails for mir's approxEqual 
because the two are not the same types (yes, I know that isClose 
in std.math works). I was trying to convert the y variable below 
to have the same double* iterator as the term on the right, but 
without much success. I tried std.conv.to and the as, slice, and 
sliced functions in mir.

I figure I am missing something basic, but I can't quite figure 
it out...


/+dub.sdl:
dependency "mir-algorithm" version="~>3.7.28"
+/

import mir.math.common: approxEqual;
import mir.ndslice.slice : sliced;

void main() {
     auto x = [0.5, 0.5].sliced(2);
     auto y = x * 5.0;

     assert(approxEqual(y, [2.5, 2.5].sliced(2)));
}


More information about the Digitalmars-d-learn mailing list