Skip to content

Instantly share code, notes, and snippets.

@dfm
Created June 16, 2011 19:39
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 dfm/1030052 to your computer and use it in GitHub Desktop.
Save dfm/1030052 to your computer and use it in GitHub Desktop.
dude.. gist it
double any_op(double, double, std::function<double(double,double)>);
int main()
{
std::function<double(double,double)> add = [](double a, double b) -> double { return a+b; };
std::function<double(double,double)> sub = [](double a, double b) -> double { return a-b; };
printf("5 + 10 = %0.2f\n", any_op(5., 10., add));
printf("5 - 10 = %0.2f\n", any_op(5., 10., sub));
return 0;
}
double any_op(double a, double b, std::function<double(double,double)> op) {
return op(a,b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment