how std::thread constructor detects rvalue reference?

后端 未结 3 1540
栀梦
栀梦 2021-01-14 11:16

Obviously it is possible to pass an rvalue reference to std::thread constructor. My problem is with definition of this constructor in cppreference. It says that

3条回答
  •  孤独总比滥情好
    2021-01-14 12:08

    The std::thread constructor knows the value category of its arguments, because it knows what Function and Args... are, which it uses to perfectly forward the its parameters to decay_copy (or equivalent).

    The actual thread function doesn't know the value category. It's always invoked as an rvalue, with all rvalue arguments - which makes sense: the copies of f and args... are local to the thread, and won't be used anywhere else.

提交回复
热议问题