How can I make the storage of C++ lambda objects more efficient?

后端 未结 5 1014
猫巷女王i
猫巷女王i 2021-02-05 07:16

I\'ve been thinking about storing C++ lambda\'s lately. The standard advice you see on the Internet is to store the lambda in a std::function object. However, none of this adv

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 07:35

    I noticed the same performance problem a while ago with MSVC10 and filed a bug report at microsoft connect :
    https://connect.microsoft.com/VisualStudio/feedback/details/649268/std-bind-and-std-function-generate-a-crazy-number-of-copy#details

    The bug is closed as "fixed". With MSVC11 developer preview your code now indeed print :

    Constructing simple!
    Copying simple!
    Moving simple!
    Destroying simple!
    5
    Destroying simple!
    Destroying simple!
    

提交回复
热议问题