On Thursday, 19 February 2015 at 10:17:47 UTC, Dicebot wrote:
Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version):

I really like mixins for this sort of thing.

```
enum signature = "void longFunction()";
version( Static )
        enum sig = "static " ~ signature;
else
        alias sig = signature;

enum funcBody =
q{{
import std.stdio : writeln;
writeln( "Hi there!" );
version( Static ) writeln( "I'm static!" );
}};

struct Mixed {
        mixin(sig ~ funcBody);
}

void main() {
        version( Static ) Mixed.longFunction();
        else {
                Mixed m;
                m.longFunction();
        }
}
```

@OP: By using a token string (q{}) for funcBody rather than a WYSIWYG string (r"" or ``), you can still get syntax highlighting in your editor.

Reply via email to