On 7/4/13 12:40 PM, w0rp wrote:
On Thursday, 4 July 2013 at 19:26:43 UTC, Jonathan M Davis wrote:
Sometimes, you're stuck, because the nature of the type that you're
dealing
with forces it to be a pure input range, but you just can't take
advantage of
many algorithms with pure input ranges, which means that you have to
write a
lot more code or use std.array.array in order to use the various
algorithms,
forcing you to allocate when it should be completely unnecessary.

That is exactly why yield is useful, because without yield, you have two
options.

1. Write a lot of code to create an InputRange. (Cost in time taken to
write it.)
2. Allocate and lose on performance. (Cost in runtime performance.)

Yield gives you option 3.

3. Write very little code while also saving on performance.

That would be a win if input ranges are very frequent. One possibility to assess that would be to figure how many algorithms in std.algorithm work with input ranges, how many generators in std.range create input ranges, and then assess the potential code savings. A consideration is also the cost of adding yield to the language (somehow this often gets neglected in the excitement of adding stuff).


Andrei

Reply via email to