2 ms·
Why did you write it with two structs though? You could do #define defer(body) DeferHolder COMMON_CAT(_defer_instance, __LINE__) {([&]()->void body)}; and
by Asooka 1y ago
Why did you write it with two structs though? You could do
#define defer(body) DeferHolder COMMON_CAT(_defer_instance, __LINE__) {([&]()->void body)};
and call it as
defer({
function body here;
});
Which looks much nicer. The preprocessor treats balanced curlies as one single token regardless of how many lines it spans, precisely to enable this usage.