Skip to content

Instantly share code, notes, and snippets.

@trnila
Created April 13, 2018 05:58
Show Gist options
  • Save trnila/bd3aa8d3fa24f15865a0787720bb7a6a to your computer and use it in GitHub Desktop.
Save trnila/bd3aa8d3fa24f15865a0787720bb7a6a to your computer and use it in GitHub Desktop.
c++ bind
#include <vector>
#include <functional>
void test(int a, int b) {
printf("%d %d\n", a, b);
}
void testStr(const char* a) {
printf("%s\n", a);
}
int main() {
std::vector<std::function<void()>> fns;
fns.push_back(std::bind(&test, 10, 20));
fns.push_back(std::bind(&test, 1000, 2000));
fns.push_back(std::bind(&testStr, "hello"));
fns.push_back(std::bind(&testStr, "world"));
for(auto &fn: fns) {
fn();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment