I\'ve written a small utility class for C++11 which I use as a scope guard for easier handling of exception safety and similar things.
Seems somewhat like a hack. Bu
We could omit the ugly [&] stuff by putting it in the define:
#define UTILITY_SCOPE_EXIT(f) const auto& _UTILITY_EXIT_SCOPE_LINENAME(EXIT, __LINE__) = ::detail::create_scope_exit([&]f)
Then:
UTILITY_SCOPE_EXIT({myfile.close();});
Tested with MSVC++ 11.0 (VS2012). Regards.