mir: How to change iterator?

WebFreak001 d.forum at webfreak.org
Fri Apr 17 08:40:36 UTC 2020


On Tuesday, 14 April 2020 at 20:24:05 UTC, jmh530 wrote:
> 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)));
> }

Use std.algorithm:equal for range compare with approxEqual for 
your comparator:

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


More information about the Digitalmars-d-learn mailing list