Created
January 5, 2017 23:02
-
-
Save JensAyton/fb3d9dacc35e001779ed57f7acb1b011 to your computer and use it in GitHub Desktop.
Something something named arguments
This file contains hidden or 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
struct ifparams { | |
#if __has_feature(objc_arc) | |
__unsafe_unretained | |
#endif | |
dispatch_block_t then, otherwise; | |
}; | |
static inline void iff(bool condition, struct ifparams params) { | |
((condition?params.then:params.otherwise)?:^{})(); | |
} | |
#define if(condition, ...) iff(condition, (struct ifparams){ __VA_ARGS__ }) | |
int main(int argc, const char * argv[]) { | |
if (5 > 3, .then = ^{ | |
printf("I can't remember why I'm doing this\n"); | |
}); | |
return 0; | |
} |
And without native control flow:
static inline void iff(bool condition, struct ifparams params) {
dispatch_block_t c1[] = { params.otherwise, params.then };
dispatch_block_t c2[] = { ^{}, c1[condition] };
c2[!!c2[1]]();
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh yea, I forgot
#define else otherwise
.