ReplaceType

Replaces all occurrences of From into To, in one or more types T. For example, ReplaceType!(int, uint, Tuple!(int, float)[string]) yields Tuple!(uint, float)[string]. The types in which replacement is performed may be arbitrarily complex, including qualifiers, built-in type constructors (pointers, arrays, associative arrays, functions, and delegates), and template instantiations; replacement proceeds transitively through the type definition. However, member types in structs or classes are not replaced because there are no ways to express the types resulting after replacement.

This is an advanced type manipulation necessary e.g. for replacing the placeholder type This in std.variant.Algebraic.

alias ReplaceType(From, To, T...) = ReplaceTypeUnless!(false_, From, To, T)

Return Value

ReplaceType aliases itself to the type(s) that result after replacement.

Examples

static assert(
    is(ReplaceType!(int, string, int[]) == string[]) &&
    is(ReplaceType!(int, string, int[int]) == string[string]) &&
    is(ReplaceType!(int, string, const(int)[]) == const(string)[]) &&
    is(ReplaceType!(int, string, Tuple!(int[], float))
        == Tuple!(string[], float))
);

Meta

Suggestion Box / Bug Report