TemplateInstanceArgs

Emulates static if (Type : Template!(Args), Args...), which is a D2 feature

Given a template and an instance of it, allows to get the arguments used to instantiate this type.

An example use case is when you want to wrap an aggregate which is templated and need your Wrapper class to be templated on the aggregate's template arguments:

class Wrapper (TArgs...) { /+ Magic stuff +/ }
class Aggregate (TArgs...) { /+ Some more magic +/ }

Wrapper!(TemplateInstanceArgs!(Aggregate, Inst)) wrap (Inst) (Inst i)
{
    auto wrapper = new Wrapper!(TemplateInstanceArgs!(Aggregate, Inst))(i);
    return wrapper;
}

This can also be used to see if a given symbol is an instance of a template: static if (is(TemplateInstanceArgs!(Template, PossibleInstance)))

Note that eponymous templates can lead to surprising behaviour:

template Identity (T)
{
    alias T Identity;
}

// The following will fail, because `Identity!(char)` resolves to `char` !
static assert(is(TemplateInstanceArgs!(Identity, Identity!(char))));

As a result, this template is better suited for template aggregates, or templates with multiple members.

template TemplateInstanceArgs (
alias Template
Type : Template!(TA)
TA...
) {}

Members

Aliases

TemplateInstanceArgs
alias TemplateInstanceArgs = TA
Undocumented in source.

Parameters

Template

The template symbol (uninstantiated)

Type

An instance of Template

Meta