Instantiate

Instantiates the given template with the given parameters.

Used to work around syntactic limitations of D with regard to instantiating a template from an alias sequence (e.g. T[0]!(...) is not valid) or a template returning another template (e.g. Foo!(Bar)!(Baz) is not allowed).

alias Instantiate(alias Template, Params...) = Template!Params

Parameters

Template

The template to instantiate.

Params

The parameters with which to instantiate the template.

Return Value

The instantiated template.

Examples

// ApplyRight combined with Instantiate can be used to apply various
// templates to the same parameters.
import std.string : leftJustify, center, rightJustify;
alias functions = staticMap!(ApplyRight!(Instantiate, string),
                             leftJustify, center, rightJustify);
string result = "";
static foreach (f; functions)
{
    {
        auto x = &f; // not a template, but a function instantiation
        result ~= x("hello", 7);
        result ~= ";";
    }
}

assert(result == "hello  ; hello ;  hello;");

Meta