diff options
Diffstat (limited to 'challenge-171/deadmarshal/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-171/deadmarshal/cpp/ch-2.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-171/deadmarshal/cpp/ch-2.cpp b/challenge-171/deadmarshal/cpp/ch-2.cpp new file mode 100644 index 0000000000..ff23f617ed --- /dev/null +++ b/challenge-171/deadmarshal/cpp/ch-2.cpp @@ -0,0 +1,17 @@ +#include<iostream> +#include<functional> + +std::function<int(int)> f = [](auto n){return n + 2;}; +std::function<int(int)> g = [](auto n){return n * 2;}; + +template<typename F, typename G> +auto compose(F f, G g) +{ + return [f,g](auto n){return f(g(n));}; +} + +int main() +{ + std::cout << compose(f, g)(5) << '\n'; + return 0; +} |
