3 ms·
template<typename T> struct __df_st : T { [[gnu::always_inline]] inline __df_st(T g) : T(g) { // empty } [[gnu::always_inline]] inline ~__df_
by 1oooqooq 2y ago
template<typename T>
struct __df_st : T {
[[gnu::always_inline]]
inline
__df_st(T g) : T(g) {
// empty
}
[[gnu::always_inline]]
inline
~__df_st() {
T::operator()();
}
};
#define __DEFER__(V) __df_st const V = [&](void)->void
#define defer __DEFER(__COUNTER__)
#define __DEFER(N) __DEFER_(N)
#define __DEFER_(N) __DEFER__(__DEFER_VARIABLE_ ## N)
#include <stdio.h>
struct S {
int r;
~S(){}
};
(i know hn will mangle this but i won't indent this on mobile...)
people really write cpp like this or is this a intentionally obscure example?
- fuhsnn 2y agoThat's from the OP blog, the intention of those macros is to generate uniquely named local lambda. Cleaner version is like: https://github.com/llvm/llvm-project/issues/100869#issue-2433451886 https://github.com/llvm/llvm-project/issues/100869#issue-243...