我可以修改函数包装器使其使用旧值吗?

Can I modify function wrapper so that it uses its old value?

本文关键字:函数 包装 我可以 修改      更新时间:2023-10-16

我可以这样修改函数包装吗

std::function<int(int)> a=[](int x){return 2*x;};
a=[f=a](int x){return f(x)+1;};

所以我可以动态地构建越来越复杂的函数?

这不起作用,主要是因为在c++ 14中引入了初始化表达式。

但是这在c++ 14中是有效的语法。以下是一些证据:http://coliru.stacked-crooked.com/a/5fe0a53953b0421b