upcastElementsTo

Upcast all elements in x of type T to the type U, where U is a superclass of T.

  1. inout(U)[] upcastElementsTo(inout(T)[] x)
  2. auto upcastElementsTo(inout(R) x)
    @trusted
    upcastElementsTo
    (
    U
    R
    )
    (
    inout(R) x
    )
    if (
    !isArray!R &&
    is(U == class)
    &&
    isInputRange!R
    &&
    is(ElementType!R == class)
    )

Examples

class X
{
    this(int x) { this.x = x; }
    int x;
}
class Y : X
{
    this(int x) { super(x); }
    int x;
}

void f2(X[2] xs) {}

Y[2] xy = [new Y(42), new Y(43)];
static assert(is(typeof(xy) == Y[2]));

// TODO: f2(xy);

Meta