Mapping with partial
matovitch via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 30 11:29:30 PDT 2015
On Monday, 30 March 2015 at 18:23:32 UTC, Adam D. Ruppe wrote:
> On Monday, 30 March 2015 at 18:07:18 UTC, matovitch wrote:
>> kmeans_example.d(79): Error: template
>> std.algorithm.iteration.map
>
> That error is easy: use points[].map!(test) instead of
> points.map.
>
> Since points is a static array, it isn't a range. Static arrays
> can't be popped through. But if you slice it, then it yields a
> usable range for map.
>
>
> The other problem though is the partial!(). It expects a
> template argument for the thing so it can make a new function
> right there at compile time... which doesn't work with a
> runtime variable.
>
> The way I'd do it is just with a little hand written delegate.
> This will compile, for example:
>
> auto test = (ref Point p) => getRandomPoint(randVar, p);
> points[].map!(test);
>
>
> and should do what you need.
Nice ! Thanks for the tip ! I tried importing std.range and
points.array works too.
More information about the Digitalmars-d-learn
mailing list