#include <iostream>
#include <functional>
template <typename nextF>
class Adder {
int sn;
static nextF next;
public:
Adder(int n)
: sn(n)
{
}
int getNext() {
sn = (*next)(sn);
return sn;
}
};
auto govnoLambda = [](int x) -> int { return x + 1;};
template <>
decltype(&govnoLambda) Adder<decltype(&govnoLambda)>::next = &govnoLambda;
int main() {
Adder< decltype(&govnoLambda) > ad(10);
std::cout << ad.getNext();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCnRlbXBsYXRlIDx0eXBlbmFtZSBuZXh0Rj4KY2xhc3MgQWRkZXIgewoJaW50IHNuOwoJc3RhdGljIG5leHRGIG5leHQ7CglwdWJsaWM6CgkJQWRkZXIoaW50IG4pCgkJCTogc24obikKCQl7CgkJfQoJCQoJCWludCBnZXROZXh0KCkgewoJCQlzbiA9ICgqbmV4dCkoc24pOwoJCQlyZXR1cm4gc247CgkJfQp9OwoKYXV0byBnb3Zub0xhbWJkYSA9IFtdKGludCB4KSAtPiBpbnQgeyByZXR1cm4geCArIDE7fTsKCnRlbXBsYXRlIDw+CmRlY2x0eXBlKCZnb3Zub0xhbWJkYSkgQWRkZXI8ZGVjbHR5cGUoJmdvdm5vTGFtYmRhKT46Om5leHQgPSAmZ292bm9MYW1iZGE7CgppbnQgbWFpbigpIHsKCUFkZGVyPCBkZWNsdHlwZSgmZ292bm9MYW1iZGEpID4gYWQoMTApOwoJc3RkOjpjb3V0IDw8IGFkLmdldE5leHQoKTsKCXJldHVybiAwOwp9