joiner and map, strange behavior

Stephan Schiffels stephan_schiffels at mac.com
Tue Mar 12 10:51:56 PDT 2013


On Tuesday, 12 March 2013 at 17:43:43 UTC, bearophile wrote:
> Stephan Schiffels:
>
>> I am struggling with understanding this behavior. In the code 
>> below, the function "getVec" is called 8 times, but it should 
>> be called only 4 times (once for each call inside of map).
>>
>> Any explanations?
>
> Maybe it's a matter of calling front() more times, as in filter 
> in a recent thread. To be sure take a look inside phobos 
> sources.
>
> By the way, your code is quite inefficient, because it 
> allocates a new matrix at each call to getVec.
>
> Bye,
> bearophile

Thanks, I had a brief look at std.algorithm.joiner but couldn't 
find anything obvious, maybe I should look deeper into it.

And yes, the example is quite bad. This version of getVec would 
have been better to illustrate:

import std.range;
auto getVec(size_t i) {
   writeln("getVec is called");
   return iota(i * 4, (i + 1) * 4);
}

Stephan


More information about the Digitalmars-d-learn mailing list