Re: Is there a way to do the same thing in entry and return of a bunch of functions?

2019-09-18 Thread Stefanos Baziotis via Digitalmars-d-learn
On Wednesday, 18 September 2019 at 01:03:27 UTC, Nicholas Wilson 
wrote:


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);


Yes that's what I meant sort of the mixin (where we can also put 
local scope inside etc.).


I mean you _could_ do some UDA reflection to generate wrapping 
function that do the indentation, bit that is overkill.


Interesting, I didn't know about that. I didn't completely get it 
but I get

that it seems the easier way to do it is the mixin.

Thanks,
Stefanos


Re: Is there a way to do the same thing in entry and return of a bunch of functions?

2019-09-17 Thread Nicholas Wilson via Digitalmars-d-learn
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.