根据c++标准,lambda函数具有唯一的类型,因此通常不能将两个lambda与?操作符结合使用。但是,正如在中所讨论的,没有捕获的lambda可以转换为函数指针。: have different types 'main()::<lambda(auto:1)>' and 'main()::<lambda(auto:2)>'
4 | <e
我刚开始学习C++ 11中的新功能,当时我正在读C++ Primer (斯坦利普曼饰)中的兰巴斯,并在试验它们。因此,我猜没有任何捕获的lambdas只是由编译器生成的普通函数,我们可以使用指向它们的普通函数指针。在使用g++时,我得到了以下编译错误:main.cpp:6:31: error: cannot convert ‘func()::__lambda0’ to
在C++11中,人们可以编写带有捕获的lambda(这太棒了!)auto myfunc = [&] (int i) {return i + j;}; // j being somewhere in the lambda's context
这太棒了!但是,如果可以从一个函数返回这样的lambda,甚至从另一个lambda返回,那就太好了。这到底有没有可能?