Aliasing a mixin (or alternative ways to profile a scope)
Johannes Loher
johannesloher at fg4f.de
Thu Mar 7 21:57:40 UTC 2019
Am 07.03.19 um 22:50 schrieb Johannes Loher:
> [...]
As a small addition, if you always want to pass the function name as a
parameter, you can simplify this to the following:
```
enum profile_scope(string name = __FUNCTION__) = "import core.stdc.stdio
: printf; printf(\""
~ name ~ "\n\"); scope(exit) printf(\"" ~ name ~ "\n\");";
extern (C) void main()
{
mixin(profile_scope!());
foo();
}
extern (C) void foo() {
mixin(profile_scope!());
}
```
This will print
```
main.main
main.foo
main.foo
main.main
```
to the commandline.
More information about the Digitalmars-d-learn
mailing list