reference to 'self' inside a function
Nick Treleaven
ntrel-public at yahoo.co.uk
Tue Sep 25 06:23:45 PDT 2012
On 25/09/2012 06:07, Rob T wrote:
> This is a little insane, but it works.
>
> int Recurse(int a)
> {
> if (a <= 1)
> return 1;
> else
> // can we replace explicit call to "Recurse"
> // with "self" using a mixin or some other means?
> // return a * Recurse(a - 1);
> mixin("return a * mixin(__traits(identifier, __traits(parent,
> {})))(a - 1);");
> }
enum string self = q{__traits(parent, {})};
int recurse(int a)
{
if (a <= 1)
return 1;
else
return a * mixin(self)(a - 1);
}
More information about the Digitalmars-d
mailing list