On Monday, 17 August 2020 at 21:18:41 UTC, Per Nordlöw wrote:
I'm using

pragma(msg, __FILE__, "(", __LINE__, ",1): Debug: ", "A useful debug message");

to print compile-time information formatted as standard compiler diagnostics.

These are picked up by Emacs Flycheck and overlayed in the editor and listen in the *Flycheck errors* buffer. Very convenient. When I want to get the type of something at compile-time.

In order to not having to repeat oneself I'm now looking for a way to extract this into a `mixin template`. Is this possible somehow and still preserve the instantiation site values of `__FILE__` and `__LINE__`?

mixin template ctLog(string msg, string file = __FILE__, size_t line = __LINE__) {
    pragma(msg, file, "(", line, "): ", msg);
}

mixin ctLog!"Module scope";
unittest {
    mixin ctLog!"function scope";
}
struct S {
    mixin ctLog!"Struct scope";
}

This works for me.

--
  Simen

Reply via email to