On Tuesday, 18 August 2020 at 08:05:20 UTC, Per Nordlöw wrote:
On Tuesday, 18 August 2020 at 08:03:04 UTC, Per Nordlöw wrote:
Forgot to mention that I want to support variadic arguments to `ctLog` similar to what is done with

And these arguments should be of any template argument kind, not only a compile-time string.

I'm not a fan of string mixins (ask Adam how they're the scourge of good programming, a wart on D's behind, and so on :p), but I found no good way to do this without them:

string ctLog(Args...)(string file = __FILE__, size_t line = __LINE__) {
    import std.conv : to;
string result = `pragma(msg, "`~file~`(", `~line.to!string~`, "): "`;
    static foreach (e; Args) {
        result ~= `, `~e.stringof;
    }
    return result~`);`;
}

mixin(ctLog!("This ", "is ", "module ", "scope."));
unittest {
    mixin(ctLog!"function scope");
}
struct S {
    mixin(ctLog!"Struct scope");
}

--
  Simen

Reply via email to