c++的currying(241) 发表于 2018-08-09 | 分类于 语言 12345678910111213141516171819202122template<typename F, typename... Args>auto partial(F f, Args... args) { return [=](auto... rest) -> auto {//草这就是c++的lamda,和js c#的完全不同啊,我这个笨蛋第一时间居然没反应过来 return f(args..., rest...); };}void demo(int a, int & b, int c, int & d) { b = b + 1; d = d + 1;}int main() { int a = 11, b = 111, c = 1111, d = 11111; std::cout << "a: " << a << " b: " << b << " c: " << c << " d: " << d << std::endl; partial(demo, a, std::ref(b))(c, std::ref(d)); std::cout << "a: " << a << " b: " << b << " c: " << c << " d: " << d << std::endl; return 0;}