function composition in C++ / C++11
Something along these lines, perhaps (untested): template <typename F> class Composer { int n_; F f_; public: Composer(int n, F f) : n_(n), f_(f) {} template <typename T> T operator()(T x) const { int n = n_; while (n–) { x = f_(x); } return x; } }; template <int N, typename F> Composer<F> compose(F … Read more