Am 07.03.19 um 22:21 schrieb Simon: > > Is there a way to achieve this while compiling with -betterC? I use a > custom string struct right now, and your version needs TypeInfo, > concatening using ~ needs the garbage collector. I have the feeling D is > really not agreeing with the way I want to do things. If this is not > possible, I will just roll with the Adam's struct solution. >
Using Adams struct solution is perfectly fine. I believe it is probably the cleaner solution overall. My solution depends on TypeInfo because format does. I used format because it makes the string more readable. You can avoid this and use string concatenation in combination with providing the function name as template parameter instead: ``` enum profile_scope(string name) = "import core.stdc.stdio : printf; printf(\"" ~ name ~ "\n\"); scope(exit) printf(\"" ~ name ~ "\n\");"; extern (C) void main() { mixin(profile_scope!"func1"); } ``` This uses string concatenation only at compile time and not during run time, so it does not require the garbage collector and is compatible with betterC :)