Filter a Range Based on a Passed In Variable
    jsako 
    spam at spam.com
       
    Sat Jan 20 19:49:18 UTC 2018
    
    
  
On Saturday, 20 January 2018 at 19:09:28 UTC, Adam D. Ruppe wrote:
> On Saturday, 20 January 2018 at 19:04:06 UTC, jsako wrote:
>> I want to be able to filter a range based on a variable known 
>> at runtime. Something like this:
>>
>> [code]
>> int id = getFilterID();
>>
>> auto filteredRange = filter!(a => a.id == 
>> id)(rangeToBeFiltered);
>>
>> [/code]
>>
>> This doesn't seem to be possible, however as .filter only 
>> takes unary predicates. I tried:
>
> That should actually work. What exactly happened when you ran 
> that literal code above?
... Huh. The code I posted was a simplified case of what I 
actually have and like a fool I didn't test it first. You're 
absolutely right, the above code does work. Color me embarrassed.
In the actual code, I kept getting DMD saying "...does not match 
template declaration filter(alias predicate) if 
(is(typeof(unaryFun!predicate)))".
I think it may be a scoping issue? I'll have to look closer at it.
Thanks for the help! Sorry I wasted your time. At least this 
pointed me in the right direction to find out what is really 
going on.
    
    
More information about the Digitalmars-d-learn
mailing list