Hello,

I am currently porting the frontend of my instrumenting profiler to D. It features a C++-makro that profiles the time between entering and leaving a scope (achieved with con-/destructors in C++). Since D has scopeguards, I hoped to achieve this by creating a mixin that generates the following code:

measure("func1");
scope(exit) measure("func1");

Since I of course don't want to type a mixin for that everytime I want to use it, I tried to alias it:

import std.meta : Alias;
alias profile_scope(string name) = Alias!(mixin("measure(\"" ~ name ~ "\"); scope(exit) measure(\"" ~ name ~ "\");"));

I expected this to generate the code above by typing profile_scope("func1") in my programm. However the compiler (dmd) gives me the following error:

source\main.d(24): Error: template plattform.profile_scope cannot deduce function from argument types !()(string), candidates are: source\plattform.d(262): plattform.profile_scope(string name)

This looks like a deduction/overload kind of error, which has me completly confused since there is no other identifier of the name "profile_scope" in my programm and the error message shows only one candidate.

Is there any way I can achive generating those two statements using only something that effectively looks like a function call/C-macro with an argument?

Reply via email to