A look inside "filter" function defintion

pascal111 judas.the.messiah.111 at gmail.com
Mon Aug 1 23:35:13 UTC 2022


This is the definition of "filter" function, and I think it 
called itself within its definition. I'm guessing how it works?

'''D
template filter(alias predicate)
if (is(typeof(unaryFun!predicate)))
{
     /**
     Params:
         range = An $(REF_ALTTEXT input range, isInputRange, 
std,range,primitives)
         of elements
     Returns:
         A range containing only elements `x` in `range` for
         which `predicate(x)` returns `true`.
      */
     auto filter(Range)(Range range) if 
(isInputRange!(Unqual!Range))
     {
         return FilterResult!(unaryFun!predicate, Range)(range);
     }
}
'''

I think this line needs explanation:

'''D
return FilterResult!(unaryFun!predicate, Range)(range);
'''


More information about the Digitalmars-d-learn mailing list