template instance cannot use local 'f' as parameter to non-global template
Tyro[a.c.edwards]
nospam at home.com
Wed Jul 13 07:58:10 PDT 2011
On 7/13/2011 11:35 PM, Trass3r wrote:
> Am 13.07.2011, 16:02 Uhr, schrieb Steven Schveighoffer
> <schveiguy at yahoo.com>:
>
>>> void h() {}
>>>
>>> class Bla
>>> {
>>> mixin wrap!h;
>>> }
>>>
>>> mixin template wrap(alias f)
>>> {
>>> void blub(alias g = f)()
>>> {
> g();
>>> }
>>> }
>
>> As a workaround, is there a reason you need blub to be parameterized?
>> I mean, f is already part of the template.
>
> Yep, a default function is passed to wrap and in most cases blub just
> calls that one.
> But sometimes I need blub to use a function other than the default one.
Don't know it this is the right answer or a possible bug but it does the
trick:
void h() { import std.stdio; write("h()"); }
class Bla
{
mixin wrap!h;
}
mixin template wrap(alias f)
{
void blub(typeof(&f) g = &f)
{
g();
}
}
void main()
{
Bla b = new Bla();
b.blub();
}
More information about the Digitalmars-d-learn
mailing list