added Drop trait to allow more automated memory management
This commit is contained in:
parent
70bbd51ef7
commit
cf001bd2d6
22
src/drop.h
Normal file
22
src/drop.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#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};\
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !_fencer_drop_h
|
Loading…
Reference in a new issue