Generic Class Alias Syntax

bearophile bearophileHUGS at lycos.com
Thu Jun 4 15:45:16 PDT 2009


eris:
> Okay.  I just assumed that since it was aliased .. and .. I included a type that matched the template parameter it should be able to sort that out.  Re-reading the syntax specs should enlighten me.<

If you want to instantiate a template and you have a value of the actual type, then there is often a way to solve the problem.
You can write a small function that performs the trick. For example you have the templated class (or struct in D2) Foo!(T), then you can define a small foo() like:

Foo!(T) foo(T)(T x) {
    return new Foo!(T)(x);
}

Now you can instantiate Foo with:
auto fint = foo(10);
auto fdouble = foo(10.0);
No stinking bangs (!) to be seen :-)
But I don't think this can be used in your situation.

Bye,
bearophile



More information about the Digitalmars-d mailing list