通常我在接受lambda作为函数的参数时使用以下模式(模板类传递值):
template <class Function>
void higherOrderFunction(Function f) {
f();
}
Run Code Online (Sandbox Code Playgroud)
这是否复制(关闭)参数?如果是这样,通过const引用接受lambda有什么不对吗?
template <class Function>
void higherOrderFunction(const Function& f) {
f();
}
Run Code Online (Sandbox Code Playgroud)
一个简单的测试似乎表明这种方法很好,但我想知道是否有任何特殊的考虑因素我应该注意.