updated mir interface

Alex sascha.orlov at gmail.com
Wed Nov 7 17:42:46 UTC 2018


On Wednesday, 7 November 2018 at 17:05:31 UTC, 9il wrote:
> I have updated template constraints.
> http://docs.random.dlang.io/latest/mir_random_algorithm.html#.sample
>
> The problem that looks like Phobos map does not define all 
> required primitives like popFrontExactly.

Ok... didn't have this on my radar.

> I suggest using Mir instead of Phobos if possible:
>
>
> https://run.dlang.io/is/NBTfwF
>
> /+dub.sdl:
> dependency "mir-algorithm" version="~>3.0.3"
> dependency "mir-random" version="~>2.1.1"
> +/
>
> import mir.random.algorithm;
> import mir.algorithm.iteration;
> import mir.ndslice: sliced, iota, map, member;
>
> void main()
> {
> 	S[] arr;
> 	arr.length = 42;
>     // using each
> 	arr.length.iota.each!((i, ref el) => el.i = i)(arr);
>
>     // or using each and member
>     arr.length.iota.each!"b = a"(arr.member!"i");
>
>     // or using assign
>     arr.member!"i"[] = arr.length.iota;
>
> 	auto res0 = rne.sample(arr.map!((ref el) => el.i), 1);
>     // or using member
> 	auto res1 = rne.sample(arr.member!"i", 1);
>
> }
>
> struct S { size_t i; }

I will try to adopt this... Thanks a lot!


More information about the Digitalmars-d-learn mailing list