cutes/drop.h

47 lines
993 B
C

#ifndef CUTES_DROP_H
#define CUTES_DROP_H
#include "typeclass_helpers.h"
#include "stddef.h"
typedef struct {
void (*const drop)(void* self);
} IDrop;
typedef struct {
void* data;
IDrop const* tc;
} Drop;
#define impl_Drop_for(T, drop_f)\
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)\
Drop T##_as_Drop(T* x) {\
static IDrop const tc = {\
.drop = default_drop,\
};\
return (Drop){.tc = &tc, .data = x};\
}
Drop float_as_Drop(float *x);
Drop float_to_Drop(float x);
Drop double_as_Drop(double *x);
Drop double_to_Drop(double x);
Drop int_as_Drop(int *x);
Drop int_to_Drop(int x);
Drop unsigned_as_Drop(unsigned *x);
Drop unsigned_to_Drop(unsigned x);
Drop size_t_as_Drop(size_t *x);
Drop size_t_to_Drop(size_t x);
#endif // !CUTES_DROP_H