SCOPE(Resource *ptr = acquire_resource(),
release_resource(ptr))
{
// do stuff with resource ptr.
}
Actually, to allow variable declarations in the init_stmt like above, you'll need to use two nested for-loops:
#define SCOPE_(name, begin_stmt, end_stmt) for (int name = 0; !name; assert(name && "should never break from a SCOPE")) for (begin_stmt; !name; name++, (end_stmt))
It is natural to add another layer of specific usage macro like this: