First-class functions: Difference between revisions

Content added Content deleted
Line 332: Line 332:


=={{header|C++}}==
=={{header|C++}}==
{{works with|C++11}}
This uses many C++0x niceties so make sure you put your compiler in the correct mode.


<lang cpp>
<lang cpp>
#include <tr1/functional>
#include <functional>
#include <vector>
#include <vector>
#include <iostream>
#include <iostream>
Line 343: Line 343:
using std::cout;
using std::cout;
using std::endl;
using std::endl;
using std::tr1::function;
using std::function;


vector<double(*)(double)> A = {sin, cos, tan, [](double x) { return x*x*x; } };
vector<double(*)(double)> A = {sin, cos, tan, [](double x) { return x*x*x; } };
Line 365: Line 365:
auto identity = compose(log10, pow);
auto identity = compose(log10, pow);
PRINT(identity(10, num));
PRINT(identity(10, num));
return 0;
}
}
</lang>
</lang>