updated mir interface

9il ilyayaroshenko at gmail.com
Wed Nov 7 17:05:31 UTC 2018


On Wednesday, 7 November 2018 at 14:46:17 UTC, Alex wrote:
> On Wednesday, 7 November 2018 at 14:07:32 UTC, 9il wrote:
>> This is a regression. It is fixed in mir-random v2.1.2.
>
> Thanks. But I have another one:
>
> ´´´
> import mir.random.algorithm;
> import std.experimental.all;
>
> void main()
> {
> 	S[] arr;
> 	arr.length = 42;
> 	arr.each!((i, ref el) => el.i = i);
> 	auto res = rne.sample(arr.map!((ref el) => el.i), 1);
> }
>
> struct S { size_t i; }
> ´´´
>
> Does not depend, on whether I use (ref el) or just el... And 
> should not depend on that ;)

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. 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; }




More information about the Digitalmars-d-learn mailing list