How do I do this?
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Thu Aug 3 05:33:54 PDT 2017
On 08/03/2017 07:00 AM, Shachar Shemesh wrote:
> No sooner did I send out this question I have found the D feature I've
> been looking for. This is what I have:
>
> module log;
>
> version(alternate_logger) {
> mixin("public import " ~ import("alternate_logger.txt") ~ ";");
> } else {
>
> // Default implementation goes here
>
> }
>
> Can't say I'm thrilled with this, but it does get the job done.
> Suggestions more than welcome.
There's a bit of irony you can read a file during compilation but not
pass a string.
The version can be dropped as well, but always requires the existence of
the intermediate file:
private alternateLogger = import("alternate_logger.txt");
static if (alternateLogger.length) {
mixin("public import " ~ alternateLogger ~ ";");
} else {
...
}
Andrei
More information about the Digitalmars-d
mailing list