Erasure

Helper mixin template wrapping functions in a foralls. Given a template symbol, a list a type variables Variables, and a name $(name), this mixin generates two symobls underscore ~ name and name. Where underscore ~ name is a private symbol with free variables and name is the former wrapped in a forall type.

// generic identity function in idiomatic D
A identityGeneric(A)(A x)
{
    return x;
}

// generate the symbol "_identityPtr" and the "identityPtr" wrapper
mixin Erasure!(identityGeneric, "identityPtr", α!("A", (void*).sizeof));

// redefine for clearity
enum Π!("A", α!("A", (void*).sizeof) function(α!("A", (void*).sizeof))) identity = identityPtr;

// usage
unittest
{
    int* x = new int(1);
    assert(*identity.specialize!(int*)()(x) == 1);
}
mixin template Erasure (
alias symbol
string name
Variables...
) {}

Members

Aliases

A
alias A = Parameters!impl
Undocumented in source.
R
alias R = ReturnType!impl
Undocumented in source.
impl
alias impl = symbol!Variables
Undocumented in source.

Meta