Function returning a lambda expression

后端 未结 6 1883
猫巷女王i
猫巷女王i 2020-11-29 18:24

I wonder if it\'s possible to write a function that returns a lambda function in C++11. Of course one problem is how to declare such function. Each lambda has a type, but th

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 19:07

    You can return lambda function from other lambda function, since you should not explicitly specify return type of lambda function. Just write something like that in global scope:

     auto retFun = []() {
         return [](int x) {return x;};
     };
    

提交回复
热议问题