On Saturday, 20 July 2019 at 09:01:21 UTC, Newbie2019 wrote:
I want to cast std.stdio : writefln into pure function pointer,
so I can call it from debug pure function.
Like the other person said, try/catch turns throws to nothrow.
The `debug` keyword disables pure checks. Those make this easy
without any mixin or wrappers/casts at all.
But even if you did want to do the mixin route, look at how
Phobos does this.
http://dpldocs.info/experimental-docs/std.traits.SetFunctionAttributes.1.html
the example of that function shows adding pure to a function
pointer. (and btw I think the phobos function itself works with
-betterC as well, you might be able to simply call it).
But then look at its implementation too:
http://dpldocs.info/experimental-docs/source/std.traits.d.html#L2354
.stringof only appears once there, for the `static assert` error
message. Everything else is direct stuff. It does string concat a
list of keywords, but they are literally written.
Then, it immediately mixes it in and thus the template returns
the generated type which is used to make an alias and a cast on
the outside, avoiding any mixin there too.