Created
July 4, 2011 03:03
-
-
Save jspahrsummers/1062849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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