Lambda Expression vs Functor in C++

后端 未结 8 803
予麋鹿
予麋鹿 2020-12-05 00:01

I wonder where should we use lambda expression over functor in C++. To me, these two techniques are basically the same, even functor is more elegant and cleaner tha

8条回答
  •  隐瞒了意图╮
    2020-12-05 00:17

    Lambdas are basically just syntactic sugar that implement functors (NB: closures are not simple.) In C++0x, you can use the auto keyword to store lambdas locally, and std::function will enable you to store lambdas, or pass them around in a type-safe manner.

    Check out the Wikipedia article on C++0x.

提交回复
热议问题