fencer/core/src/drop.h
2023-11-22 11:45:58 +01:00

32 lines
672 B
C

#ifndef _fencer_drop_h
#define _fencer_drop_h
typedef struct {
void (*const drop)(void* self);
} IDrop;
typedef struct {
void const* data;
IDrop const* tc;
} Drop;
#define impl_Drop_for(T, drop_f)\
static inline Drop T##_as_Drop(T* x) {\
TC_FN_TYPECHECK(void, drop_f, T*);\
static IDrop const tc = {\
.drop = (void(*const)(void*)) drop_f,\
};\
return (Drop){.tc = &tc, .data = x};\
}
extern void default_drop(void*);
#define impl_default_Drop_for(T)\
static inline Drop T##_as_Drop(T* x) {\
static IDrop const tc = {\
.drop = default_drop,\
};\
return (Drop){.tc = &tc, .data = x};\
}
#endif // !_fencer_drop_h