Can lambda functions be templated?

前端 未结 11 2538
你的背包
你的背包 2020-11-28 01:44

In C++11, is there a way to template a lambda function? Or is it inherently too specific to be templated?

I understand that I can define a classic templated class/fu

11条回答
  •  一向
    一向 (楼主)
    2020-11-28 02:05

    I wonder what about this:

    template 
    inline std::function templateLamda() {
      return [](){ std::cout << something.memberfunc() };
    }
    

    I used similar code like this, to generate a template and wonder if the compiler will optimize the "wrapping" function out.

提交回复
热议问题