Is there a way to do the same thing in entry and return of a bunch of functions?
Nicholas Wilson
iamthewilsonator at hotmail.com
Wed Sep 18 01:03:27 UTC 2019
On Tuesday, 17 September 2019 at 17:11:09 UTC, Stefanos Baziotis
wrote:
> I think it's better to give a concrete example rather than
> explaining this vaguely.
>
> -- The question --
> Can we do better ? For one, I believe that because D does not
> have a preprocessor,
> we have to do an actual declaration which would be somewhat
> more verbose.
> Or do a mixin that does it. mixin can help as it can be more
> complicated
> and also we can access local scope (although I don't think this
> is a good idea).
>
> But in both cases, they're not totally invisible.
>
> Can we do something like: func1, func2 and func3, when they
> enter do the X
> and when they return, they do the Y.
>
> Thanks,
> Stefanos
I think a mixin that does
string LOG_SCOPE = q{
callDepth++;
scope(exit) callDepth--;
}
is probably the easiest. for bonus points
string LOG_SCOPE = q{
callDepth++;
debug_log(__FUNCTION__);// or __PRETTY_FUNTION__
scope(exit) callDepth--;
}
and the mixin(LOG_SCOPE);
I mean you _could_ do some UDA reflection to generate wrapping
function that do the indentation, bit that is overkill.
More information about the Digitalmars-d-learn
mailing list