Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
typedef id (^Tuple)(size_t);
#define tuple(...) \
tupleMake(__VA_ARGS__, nil)
#define emptyTuple \
tupleMake(nil)
Tuple tupleMake (id firstObject, ...) NS_REQUIRES_NIL_TERMINATION
{
if (!firstObject) {
Tuple t = ^ id (size_t n){
return nil;
};
return [[t copy] autorelease];
}
// blah blah get varargs here
size_t numberOfObjects;
id objects[numberOfObjects];
Tuple t = ^ id (size_t n){
if (n < numberOfObjects)
return objects[n];
else
return nil;
};
return [[t copy] autorelease];
}
// usage
Tuple t = tuple(@"foo", [NSNumber numberWithInt:1]);
NSString *str = t(0);
NSNumber *num = t(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment