Mixin Global Variables
Jarrett Billingsley
kb3ctd2 at yahoo.com
Mon Mar 17 07:05:28 PDT 2008
"Brian White" <bcwhite at pobox.com> wrote in message
news:frlpm6$3km$1 at digitalmars.com...
>I want to create a module/global variable as the result of a template
>mixin. However, this variable needs some sort of "static this"
>initialization.
>
> Is this possible with a single mixin? (i.e. declare the variable AND
> create a static initializer for it)
It should be.
If you're using a template mixin:
template foo(T)
{
T bar;
static this()
{
bar = something();
}
}
mixin foo!(int);
If you're using a string mixin:
template foo(T)
{
const char[] foo =
T.stringof ~ ` bar;
static this()
{
bar = something();
}`;
}
mixin(foo!(int));
More information about the Digitalmars-d-learn
mailing list