I have a macro which I use to log, and within the macro I'd like to define a temprecord as follows:
#define MACRO_LOG(...) \
temprecord t; \
logger->logmessage(__VA_ARGS___);
with temprecord() { logger->increaseIndent() }
and in the destructor a decreaseIndent()
.
The association with a name (e.g., variable) gives an object scope which controls its lifetime. By not naming an object, it's lifetime is bound
source Why do un-named C++ objects destruct before the scope block ends?
Because the temprecord has lifetime of the scope, if I have
{
MACRO_LOG("stackoverflow example");
MACRO_LOG("stackoverflow example");
}
Outside the scope I will have 0 indent and in the scope 1 and 2 indents. However, as I name my temprecord t I get a redefinition of variable names.. and if I do not declare it I do not get the scope that I want.
How to go about this? I thought of using a container to put the temprecords in, but can't seem to solve the puzzle..
What I wish to accomplish is double indentation in my mentioned scope, and not single indentation within the MACRO_LOG scope.