Captureless lambda cannot be converted to function pointer when stored in std::function

后端 未结 1 1865
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 05:36

Usually, a C++ lambda without a capture should be convertable to a c-style function pointer. Somehow, converting it using std::function::target does not work (i

相关标签:
1条回答
  • 2020-12-31 06:12

    In your first call, std::function does not bother with decaying the lambda into a pointer, it just stores it, with its actual type (which is indeed not void()).

    You can force the lambda to decay into a pointer before constructing the std::function with the latter by simply using a unary +:

    callMe(+[](){});
    //     ^
    
    0 讨论(0)
提交回复
热议问题