1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #include <functional> #include <utility>
template <class Fun> class y_combinator_result { Fun fun_;
public: template <class T> explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {} template <class... Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template <class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }
|