Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在定义带有函数参数的函数时,我应该std::function通过复制、引用还是 const 引用来接收 lambda/?
std::function
还是三个都行?
我会选择 const ref。const 是因为函数不应该被更改,而 ref 是因为接受参数的函数不必检查 null。
但不要相信我的话,这将取决于具体情况。这是一个提供其他观点的重复帖子:
我应该通过 const-reference 传递 std::function 吗?