Created
June 26, 2012 05:31
-
-
Save kakkun61/2993526 to your computer and use it in GitHub Desktop.
[solved] Why is std::tr1::bad_function_call thrown?
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
#include<iostream> | |
#include<functional> | |
#include<cmath> | |
using namespace std; | |
using namespace std::tr1; | |
template<typename Param, typename Middle, typename Result> | |
function<Result(Param)> compose(const function<Result(Middle)>& f, const function<Middle(Param)>& g) { | |
return [f, g](Param x){return f(g(x));}; | |
} | |
int main(void) { | |
function<double(double)> f = [](double x){return exp(x);}; | |
function<double(double)> g = [](double x){return pow(x, 2);}; | |
function<double(double)> h = [](double x){return -x + 1;}; | |
function<double(double)> &composed = compose(compose(f, g), h); | |
cout << composed(10) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment