using namespace std;
template <typename T>
auto x(function<T(T)> f, T t = {}) {
return [=] {
T static x = t;
return x = f(x);
};
}
function f {[] (int x) { return x + 1; }};
function g {x(f)};
func generator() chan int {
ch := make(chan int, 16)
go func() {
defer close(ch)
timeout := time.After(2 * time.Minute)
for i := 0; i < 1024; i++ {
select {
case ch <- i:
case <-timeout:
return
}
}
}()
return ch
}
using namespace std;
template <typename T>
auto x(function<T(T)> f, T t = {}) {
return [=] {
T static x = t;
return x = f(x);
};
}
function f {[] (int x) { return x + 1; }};
function g {x(f)};