Hello,
I wish to have a conditional statement, followed immediately by an object instanciation that will automatic clean-up at the end of a scope, a little bit similar to following example:
if (conditionRealized)
{
// do something
}
which effectively would translate into something like:
if (conditionRealized)
{
DummyObject dummy(initializationType);
// do something
}
in above example, the destructor of dummy can automatically clean-up various things.
I have to place such a construct into several hundreds of functions, and I wish to simplify the task with a preprocessor command, so that I will be able to write:
IF_CONDITION_REALIZED_THEN
{
// do something
}
but above construct does obviously not work, since the scope comes after the preprocessor command.
I could use a preprocessor like:
#define IF_CONDITION_REALIZED_THEN if(conditionRealized) { DummyObject dummy(initializationType);
in order to write my code like:
IF_CONDITION_REALIZED_THEN
// do something
}
but my code editor doesn't like this (puts wrong indents), and it looks ugly.
Any idea?
Or, to present my problem in a different light:
I have a condition, that if passed, needs to make sure something is executed at the end of the scope, similar to this example:
if (canLockOtherThreads())
{
// do something
unlockOtherThreads();
}