Last active
August 5, 2022 17:50
-
-
Save theoknock/5c52fb4bddeba7257d9c24f95ce07e0d to your computer and use it in GitHub Desktop.
Generic function using id type
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
static int counter = 0; | |
// ... | |
id (^retainable_object_)(id(^)(void)) = ^ id (id(^object)(void)) { | |
return ^{ | |
return object(); | |
}; | |
}; | |
id (^(^retain_object_)(id(^)(void)))(void) = ^ (id(^retainable_object)(void)) { | |
id retained_object = retainable_object(); | |
return ^ id { | |
return retained_object; | |
}; | |
}; | |
static unsigned long (^(^iterator_)(const unsigned long))(id(^)(void)) = ^ (const unsigned long object_count) { | |
typeof(id(^)(void)) retained_objects_ref; | |
return ^ (id * retained_objects_t) { | |
static typeof(unsigned long(^)(unsigned long)) recursive_iterator_; | |
return ^ (id(^object)(void)) { | |
return (recursive_iterator_ = ^ unsigned long (unsigned long index) { | |
printf("index population count == %lu (object %lu of %lu)\n", index/*((~index + 1UL) & index)*/, [(NSNumber *)(object()) unsignedLongValue], object_count); | |
return ((index) >> 1UL) && (recursive_iterator_)((index) >> 1UL); | |
})((1UL << object_count) >> 1UL); | |
}; | |
}((id *)&retained_objects_ref); | |
}; | |
// .... | |
id (^object_)(void) = ^{ | |
NSNumber * number = @(++counter); | |
return number; | |
}; | |
iterator_(5)(object_); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment