On Tuesday, 15 March 2016 at 04:05:11 UTC, Meta wrote:
I believe this should work with the latest DMD:
alias castRange(T) = t => t.map!(x => cast(T) x).filter!(x => x
!is null);
No it does not.
However this works :
auto typeFilter(T, Range)(Range range) {
import std.algorithm : filter, map;
import std.traits : ForeachType;
static assert(is(T == class) && is(T : ForeachType!Range),
"typeFilter only works with classes that are derived form each
other");
return range.map!(x => cast(T) x).filter!(x => x !is null);
}
You're Welcome.