castFilter

Variant of std.algorithm.iteration : that filters out all elements of range that are instances of Subclass.

template castFilter(Subclass)
castFilter
(
Range
)
(
Range range
)
if (
isInputRange!(Range) &&
is(ElementType!Range == class)
&&
is(Subclass : ElementType!Range)
)

Examples

1 class X
2 {
3     this(int x)
4     {
5         this.x = x;
6     }
7     int x;
8 }
9 
10 class Y : X
11 {
12     this(int x)
13     {
14         super(x);
15     }
16 }
17 
18 auto y = castFilter!Y([new X(42), new Y(43)]);
19 auto yf = y.front;
20 static assert(is(typeof(yf) == Y));
21 y.popFront();
22 assert(y.empty);

Meta