getNext

Timon Gehr timon.gehr at gmx.ch
Mon Jul 9 14:08:29 PDT 2012


On 07/09/2012 11:04 PM, Andrei Alexandrescu wrote:
> On 7/9/12 4:47 PM, Mehrdad wrote:
>> I mean like, why isn't it defined this way instead?
>>
>> void transform(alias f, RI, RO)(RI r, RO output)
>>     if(isInputRange!RI && isOutputRange!RO)
>> {
>>     for(; !r.empty; r.popFront())
>>     output.put(unaryFun!f(r.front));
>> }
>
> Instead of what? There is not transform() function in std.algorithm.
>
> Andrei

His post was related to this one, burried in another branch of the
thread:

On 07/09/2012 08:33 PM, jerro wrote:
> It is useful to be able to write an algorithm that both reads
> and writes range elements. There are plenty of use cases for
> that, but if you really need an example, here's a simple one:
>
> void transform(alias f, R)(R r)
>      if(isInputRange!R && hasAssignableElements!R)
> {
>      for(; !r.empty; r.popFront())
>          r.front = unaryFun!f(r.front);
> }



More information about the Digitalmars-d mailing list