algorithm's .filter!() by range key

Charles via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 9 12:54:25 PST 2016


On Tuesday, 9 February 2016 at 20:48:01 UTC, Steven Schveighoffer 
wrote:
> On 2/9/16 3:40 PM, Charles wrote:
>> This seems to be true of any range function really... is there 
>> a way to
>> access the key within my range?
>>
>> Example of what I want to do:
>>
>> auto x = [1,2,3,4,5];
>> x.filter( x_key % 2 == 1 ).sum(); // sum odd elements in array
>
> An array is not an indexed range. It only works with foreach by 
> key because of special foreach behavior.
>
> What you want is std.range.enumerate


Exactly! Thanks!

Interestingly, hackerrank doesn't seem to have it. They're using 
2.067.0-b1 on Ubuntu 14.04.



More information about the Digitalmars-d-learn mailing list