Eliminating code duplication for static/nonstatic functions

deadalnix deadalnix at gmail.com
Sat Sep 21 06:21:46 PDT 2013


On Friday, 20 September 2013 at 15:20:36 UTC, Andrei Alexandrescu 
wrote:
> 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

You'll be very disapointed when some of your overloads will 
disapear.


More information about the Digitalmars-d mailing list