-
-
Save flowblok/3883065 to your computer and use it in GitHub Desktop.
Awesome hacky code!
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
// I've left parameters as-is, but success / failure might be constants? | |
// (if so, hash define them) | |
// also, I would usually pass in the records directly, rather than using | |
// global variables: | |
// Record *records, | |
// size_t n_records, | |
// | |
void list_generator( | |
int (*process)(Record, string[]), | |
string options[], | |
string success, | |
string failure | |
) { | |
size_t n_matched = 0; | |
// what's up with your <= ? | |
// is recordcount not actually a count, but actually the last index? | |
for (int i = 0; i <= recordcount; i++) { | |
Record r = records[i]; | |
if ((*process)(r, options) > 0) { | |
// if this is the first matched record, | |
// print the success string | |
if (!n_matched) | |
cout << success; | |
n_matched++; | |
// then print the record title | |
cout << r.title << endl; | |
} | |
} | |
// if no records were matched, | |
// print the failure string | |
if (!n_matched) | |
cout << failure; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment