I was getting tired of repeating types when writing things like this:
NSDictionary* d = @{@"so": [NSNumber numberWithInt:index]),
@"much": [NSNumber numberWithBool:accepted]),
@"repeat": [NSNumber numberWithDouble:height]};
So I defined a generic macro (a new feature in C11):
#define box(X) _Generic((X), \
char: boxChar, \
unsigned char: boxUnsignedChar, \
short: boxShort, \
unsigned short: boxUnsignedShort, \
int: boxInt, \
unsigned int: boxUnsignedInt, \
long: boxLong, \
unsigned long: boxUnsignedLong, \
long long: boxLongLong, \
unsigned long long: boxUnsignedLongLong, \
float: boxFloat, \
double: boxDouble, \
BOOL: boxBool \
)(X)
... implement type-specific box methods as well ...
So that I could write things like this:
NSDictionary* d = @{@"so": box(index),
@"much": box(accepted),
@"shorter": box(height)};
Is this a good idea? Can I expect others to be able to build the code? Will they hate it for not being standard?