What is the rationale behind std::bind and std::thread always copying arguments?

前端 未结 5 1382
你的背包
你的背包 2021-02-20 03:35

It\'s pretty well known that the default behaviour of std::bind and std::thread is that it will copy (or move) the arguments passed to it, and to use reference semantics we will

5条回答
  •  我在风中等你
    2021-02-20 04:27

    std::bind creates a callable which is detached from the call site of std::bind, thus it makes much sense to capture all arguments by value by default.

    The general use case is to be identical to passing a function pointer to a function without knowing where it might end up.

    Lambdas give more flexibility for the programmer to decide whether the lambda will live beyond the scope arguments are captured from.

提交回复
热议问题