Function composition: Difference between revisions

Add C++20, clean-up
m (→‎Python Multiple composition: Updated primitive, tidied.)
(Add C++20, clean-up)
Line 749:
std::function<double(double)> g = asin;
std::cout << compose(f, g)(0.5) << std::endl;
 
return 0;
}</lang>
 
Line 765 ⟶ 763:
int main() {
std::cout << compose(sin, asin)(0.5) << "\n";
return 0;
}</lang>
{{untested|cpp}}
 
{{works with|GCC}} GCC'sNot standard C++, librarybut GCC has a built-in compose function
<lang cpp>#include <iostream>
#include <cmath>
Line 776 ⟶ 772:
int main() {
std::cout << __gnu_cxx::compose1(std::ptr_fun(::sin), std::ptr_fun(::asin))(0.5) << std::endl;
 
return 0;
}</lang>
 
'''Works with:''' C++20
<lang cpp>#include <iostream>
#include <cmath>
auto compose(auto f, auto g) {
return [=](auto x) { return f(g(x)); };
}
 
int main() {
std::cout << compose(sin, asin)(0.5) << "\n";
}
</lang>
{{out}}
<pre>
0.5</pre>
 
=={{header|Clojure}}==
125

edits