std.range lockstep is not input range but opApply entity. Workarounds?

mist none at none.none
Sat Dec 29 07:42:44 PST 2012


Any objections to documentation update to cross-reference zip and 
lockstep to each other? Was not even searching for first one when 
found lockstep, huh.

On Saturday, 29 December 2012 at 14:19:39 UTC, Simen Kjaeraas 
wrote:
> On 2012-48-29 14:12, mist <none at none.none> wrote:
>
>> I basically want to be able to do stuff like this:
>> auto result = map!( (a, b) => a+b )( lockstep(range1, range2) 
>> );
>>
>> Are there any standard short ways to wrap an input range 
>> around struct with opApply (which Lockstep is)?
>>
>> Also what about redesigning Lockstep as a proper range? I 
>> could do a pull request but not sure about current intentions.
>
> Use std.range.zip instead:
>
>   auto result = map!( (a, b) => a+b )( zip(range1, range2) );
>
> The reason there are two ways is lockstep works better with 
> foreach:
>
>   foreach (a, b; lockstep(A, B) ) {
>       // Use a and b here.
>   }
>
> Contrast with zip:
>
>   foreach (a; zip(A, B) ) {
>       // Use a[0] and a[1] here.
>   }
>
> There have been suggestions to better integrate tuples in the 
> language,
> so in the future zip may have all the advantages of lockstep 
> (and vice
> versa), but don't cross your fingers.



More information about the Digitalmars-d-learn mailing list