std.algorithm and templates

meat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 10 17:24:47 PST 2014


Hello! Thanks for the notice. I've been enjoying delving into D 
recently, and have made quite some progress, but I've become 
stumped on this one problem!
I consider myself decent at natural debugging, but this problem 
has eluded me.

I don't believe any of this problem is implementation specific to 
the rest of my project, but please note if this is too vague. I'm 
defining something like..

class Woah(){}
class Bro: Woah{}
DList!Woah woahs;

and I'm having trouble with..

foreach( bro; woahs.filter!( a => cast(Bro)a !is null))

I'd figure that this would enumerate a collection of Woahs that 
are in fact Bros. Maybe I'm just spoiled by Linq.
Instead, I'm getting hit by this.

Error: template std.algorithm.filter cannot deduce function from 
argument types !()(DList!(Woah), void), candidates are:
..\src\phobos\std\algorithm.d(1628):
std.algorithm.filter(alias pred) if (is(typeof(unaryFun!pred)))

[ Likewise if I specify by filter!( func)( collection) ]

It seems to me that maybe it's a problem with the predicate I'm 
supplying; even though it's unary.
Any help, or how I can proceed and remove my eyesore placeholder 
will be greatly appreciated.
Thanks!


More information about the Digitalmars-d-learn mailing list