mir: How to change iterator?

9il ilyayaroshenko at gmail.com
Mon Apr 20 00:27:40 UTC 2020


On Sunday, 19 April 2020 at 22:07:30 UTC, jmh530 wrote:
> On Thursday, 16 April 2020 at 20:59:36 UTC, jmh530 wrote:
>> [snip]
>>
>> /+dub.sdl:
>> dependency "mir-algorithm" version="~>3.7.28"
>> +/
>>
>> import mir.ndslice;
>>
>> void foo(Iterator, SliceKind kind)(Slice!(Iterator, 1, kind) 
>> x, Slice!(Iterator, 1, kind) y) {
>>     import std.stdio : writeln;
>>     writeln("here");
>> }
>>
>> void main() {
>>     auto x = [0.5, 0.5].sliced(2);
>>     auto y = x * 5.0;
>>     foo(x, y);
>> }
>
> This is really what I was looking for (need to make allocation, 
> unfortunately)
>
> /+dub.sdl:
> dependency "mir-algorithm" version="~>3.7.28"
> +/
>
> import mir.ndslice;
>
> void foo(Iterator, SliceKind kind)(Slice!(Iterator, 1, kind) x, 
> Slice!(Iterator, 1, kind) y) {
>     import std.stdio : writeln;
>     writeln("here");
> }
>
> void main() {
>     auto x = [0.5, 0.5].sliced(2);
>     auto y = x * 5.0;
>     foo(x, y.slice);
> }

Using two arguments Iterator1, Iterator2 works without allocation

/+dub.sdl: dependency "mir-algorithm" version="~>3.7.28" +/
import mir.ndslice;

void foo(Iterator1, Iterator2, SliceKind kind)
  	(Slice!(Iterator1, 1, kind) x, Slice!(Iterator2, 1, kind) y)
{
     import std.stdio : writeln;
     writeln("here");
}

void main() {
     auto x = [0.5, 0.5].sliced(2);
     auto y = x * 5.0;
     foo(x, y);
}



More information about the Digitalmars-d-learn mailing list