Eliminating code duplication for static/nonstatic functions
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Sep 20 08:20:34 PDT 2013
On 9/19/13 1:02 PM, Andrej Mitrovic wrote:
> On 9/19/13, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
>> I'm not sure I understand how that would work.
>
> -----
> module test;
[snip]
Thanks, that's the simplest and most effective. I reduced it to:
struct A
{
enum hasState = false;
private mixin template funDef()
{
void fun(int x) { writeln(x); }
}
static if (hasState)
mixin funDef!();
else
static mixin funDef!();
}
void main()
{
A a;
a.fun(42);
}
I see no way to extract the scaffolding into a library.
Andrei
More information about the Digitalmars-d
mailing list