Question about explicit template instantiation
Edward Diener
eddielee_no_spam_here at tropicsoft.com
Sat Feb 9 15:55:58 PST 2008
I am working my way throught the pdf documentation ( 1.0 ) regarding
templates in D and in the topic about explicit template instantiation
and I came across the lines below, which have me stumped:
----------------------------------------------------------------
A template instantiation can be aliased:
template TFoo(T) { alias T* t; }
alias TFoo!(int) abc;
abc.t x; // declare x to be of type int*
Multiple instantiations of a TemplateDeclaration with the same
TemplateArgumentList, before
implicit conversions, all will refer to the same instantiation. For example:
template TFoo(T) { T f; }
alias TFoo!(int) a;
alias TFoo!(int) b;
...
a.f = 3;
assert(b.f == 3); // a and b refer to the same instance of TFoo
This is true even if the TemplateInstances are done in different modules.
----------------------------------------------------------------
My confusion with the above is that an alias, when referring to a type,
is the equivalent of a C++ typedef AFAICS. So 'a' and 'b' above are
types ( because the instantiated template is a type ) and then I see the
'a.f=3' line followed by the 'assert(b.f == 3)' line and I can not
understand how a type can be used in either expression.
I am also assuming that the line beginning with "Multiple instantiations
of a..." only mean that the 'a' and 'b' refer to the same type, but
perhaps I have missed something in this explanation.
More information about the Digitalmars-d
mailing list