26 lines
749 B
C
26 lines
749 B
C
#ifndef PUREOPTION_H
|
|
#define PUREOPTION_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
#define pureoption_some(x) \
|
|
({ \
|
|
static typeof(x) _temp = (x); \
|
|
_pureoption_some(&_temp); \
|
|
})
|
|
|
|
#define pureoption_get(x_type, x) *(x_type *)_pureoption_get(x)
|
|
|
|
typedef struct {
|
|
bool has_value;
|
|
void *value;
|
|
} pureoption;
|
|
|
|
pureoption _pureoption_some(void *value);
|
|
pureoption pureoption_none(void);
|
|
bool pureoption_has(pureoption option);
|
|
bool pureoption_lacks(pureoption option);
|
|
void *_pureoption_get(pureoption option);
|
|
|
|
#endif // PUREOPTION_H
|