All pastes #2075089 Raw Edit

Someone

public cpp v1 · immutable
#2075089 ·published 2011-06-05 14:58 UTC
rendered paste body
#include <functional>#include <cstdio>template <typename R, typename V1, typename V2>std::function<R(V2)> pa(const std::function<R(V1,V2)> &f, V1 v) {    return [&](V2 x) { return f(v, x); };}template <typename R, typename V1, typename V2>std::function<std::function<R(V1)>(V2)> curry(const std::function<R(V1,V2)> &f) {    return [&](V2 x) { return pa(f, x); };}template <typename Lhs, typename Rhs>auto times(const Lhs &lhs, const Rhs &rhs) -> decltype(lhs * rhs) {	return lhs * rhs;}int main() {	std::function<int(int, int)> itimes = times<int, int>;		printf("pa: %d\n", pa(itimes, 10)(20));	printf("curry: %d\n", curry(itimes)(10)(20));}