Lets ask you about this simple scope guard:
template <class T>
struct finop_t {
T& t;
~finop_t() { t(); }
};
#define FINALLY__(l, cl) \
auto FIN ## l ## clo = cl; \
finop_t<decltype(FIN ## l ## clo)> FIN ## l ## fin { FIN ## l ## clo}
#define FINALLY_(l, cl) FINALLY__(l, cl)
#define FINALLY(...) FINALLY_(__LINE__, ([=](){__VA_ARGS__}))
int main() {
FINALLY( std::cout << "hello" << std::endl ; );
std::cout << "one" << std::endl;
FINALLY( std::cout << "world" << std::endl ; );
std::cout << "second" << std::endl;
return 0;
}
Is it safe to rely on destruction order here? i.e. is it safe assume that ~finop_t()
will be called before lambda destructor?