Andrey Semashev
Also, your macro requires the type to be movable. This seems like a rather strong requirement. For instance, it won't work with lock_guard. If you really want to improve it you might want to use 'for' statement instead of 'if', something along these lines:
template< typename T > struct with_value { T value; bool guard; };
#define BOOST_WITH(x)\ for (with_value
w{x, true}; w.guard; w.guard=false)
Hi Andrey, Sorry, didn't get the idea. How does for loop solve the problem with non-movable types? I'd also note that it's possible to do that as follows #define WITH_IMP(code) code } #define WITH(x) {const decltype(x)& _unique = x; (void)_unique; WITH_IMP std::mutex m; WITH(std::lock_guardstd::mutex{}) ( do_something(); ) But in this case habitual brace syntax is lost. So after all I would rather stick to usual C++ scoped style.