The lifetime of reduce's internal seed

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 25 23:24:26 PDT 2014


On 04/22/2014 11:45 AM, monarch_dodra wrote:

 > Reduce returns "the seed". It's actually doing something more like this:
 >
 > int[1] foo()
 > {
 >      int[1] sum
 >      sum = sum[]; //The lambda operates, and the
 >                   //result is assigned back to the seed.
 >      return sum; //Returns the seed.
 > }

My original lambda that returned a slice was correct then. The seed 
would eventually be copied out. Had the compiler not allow slicing the 
rvalue then I would be in good shape.

 > BTW, I'm re-implemented reduce recently (not yet pulled), but I was
 > *very* thorough about documenting what it does:
 > https://github.com/D-Programming-Language/phobos/pull/2060
 >
 > Could you take a look at it (the documentation I mean), and tell me if
 > everything is what you would have expected?

I think it looks great! :)

Two comments/questions which I did not make on github:

1) Some of the documentation comments that are inside a scope are not 
formatted as such. For example, this comment does not start with /++ :

 
https://github.com/monarchdodra/phobos/blob/reduceReimpl/std/algorithm.d#L753

I wonder whether they are still included in the produced documentation.

2) I think even single-line code blocks should have curly brackets but 
Phobos code does not follow that guideline. :)

Ali



More information about the Digitalmars-d-learn mailing list