digitalmars.D.learn - std.algorithm and templates
- meat (26/26) Dec 10 2014 Hello! Thanks for the notice. I've been enjoying delving into D
- bearophile (10/15) Dec 10 2014 import std.algorithm, std.container;
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!
Dec 10 2014
meat:class Woah(){} class Bro: Woah{} DList!Woah woahs; and I'm having trouble with.. foreach( bro; woahs.filter!( a => cast(Bro)a !is null))import std.algorithm, std.container; class Woah {} class Bro : Woah {} void main() { DList!Woah woahs; foreach (bro; woahs[].filter!(a => cast(Bro)a !is null)) {} } Bye, bearophile
Dec 10 2014