Skip to content

Instantly share code, notes, and snippets.

@flowblok
Forked from harrisony/gist:3877260
Created October 13, 2012 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flowblok/3883065 to your computer and use it in GitHub Desktop.
Save flowblok/3883065 to your computer and use it in GitHub Desktop.
Awesome hacky code!
// 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