Can a call to pragma(msg, __FILE__, ...) be mixin templatized?
Simen Kjærås
simen.kjaras at gmail.com
Mon Aug 17 22:37:12 UTC 2020
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
More information about the Digitalmars-d-learn
mailing list