lockstep works with .each, but fails with .map

realhet real_het at hotmail.com
Fri Mar 5 18:49:09 UTC 2021


Hi
What am I doing wrong here?

import std.stdio, std.range, std.algorithm, std.uni, std.utf, 
std.conv, std.typecons, std.array;

auto SE(A, B)(in A a, in B b){
     return (a-b)^^2;
}

void main(){
     auto a = [1, 2, 3], b = [1, 1, 1];
     lockstep(a, b, StoppingPolicy.requireSameLength).each!((a, 
b){ writeln(SE(a, b)); });
     lockstep(a, b, StoppingPolicy.requireSameLength).map !((a, 
b){ return  SE(a, b) ; }).each!writeln;  <- error here
}

The error:
map(Range)(Range r)
   with Range = Lockstep!(int[], int[])
   must satisfy the following constraint:
        isInputRange!(Unqual!Range)

Why it works with each (or foreach), but not with map? o.O

I just wanted to make a Sum of squared errors function.

Thanks in advance!


More information about the Digitalmars-d-learn mailing list