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)
    version(none)
    @trusted
    inout(U)[]
    upcastElementsTo
    (
    U
    T
    )
    (
    return scope inout(T)[] x
    )
    if (
    is(T == class) &&
    is(U == class)
    )
  2. auto upcastElementsTo(inout(R) x)

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