#include <iostream>
#include <functional>
int add(int a, int b)
{
return a + b;
}
template <typename T1, typename T2, typename T3>
std::function<T1(T3)> curry(std::function<T1(T2, T3)> f, T2 a)
{
return [=](T3 b) -> T1 { return f(a, b); };
}
template <typename T1, typename T2, typename T3>
inline std::function<T1(T3)> curry(T1(*f)(T2, T3), T2 a)
{
return curry(std::function<T1(T2, T3)>(f), a);
}
int main()
{
std::function<int(int)> add1 = curry(add, 1);
std::cout << add1(2) << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCmludCBhZGQoaW50IGEsIGludCBiKQp7CiAgICByZXR1cm4gYSArIGI7Cn0KCnRlbXBsYXRlIDx0eXBlbmFtZSBUMSwgdHlwZW5hbWUgVDIsIHR5cGVuYW1lIFQzPgogICAgc3RkOjpmdW5jdGlvbjxUMShUMyk+IGN1cnJ5KHN0ZDo6ZnVuY3Rpb248VDEoVDIsIFQzKT4gZiwgVDIgYSkKewogICAgcmV0dXJuIFs9XShUMyBiKSAtPiBUMSB7IHJldHVybiBmKGEsIGIpOyB9Owp9Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVDEsIHR5cGVuYW1lIFQyLCB0eXBlbmFtZSBUMz4KICAgIGlubGluZSBzdGQ6OmZ1bmN0aW9uPFQxKFQzKT4gY3VycnkoVDEoKmYpKFQyLCBUMyksIFQyIGEpCnsKICAgIHJldHVybiBjdXJyeShzdGQ6OmZ1bmN0aW9uPFQxKFQyLCBUMyk+KGYpLCBhKTsKfQoKaW50IG1haW4oKQp7CiAgICBzdGQ6OmZ1bmN0aW9uPGludChpbnQpPiBhZGQxID0gY3VycnkoYWRkLCAxKTsKICAgIHN0ZDo6Y291dCA8PCBhZGQxKDIpIDw8IHN0ZDo6ZW5kbDsKfQo=