1
我有一个问题,哪种方式最好将向量转发到绑定函数?std :: bind - vector作为绑定函数中的参数
下面是两种方法的代码。在生产代码向量中将包含大量的数据,我想尽可能避免复制它。
我会很乐意提供任何提示和解释。谢谢。
#include <iostream>
#include <vector>
#include <functional>
void foo(const std::vector<uint16_t>& v)
{
for(const auto& c : v)
{
std::cout << c;
}
std::cout << std::endl;
}
int main()
{
std::vector<uint16_t> vv{1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
auto f1 = std::bind(&foo, vv); // 1)
auto f2 = std::bind(&foo, std::move(vv)); // 2)
f1();
f2();
}
你有什么问题,你有代码,你告诉我们?你只是想对你应该使用哪两个'std :: bind'调用发表意见? –
是的,我想阅读您的意见,哪种方法是最好的(从性能POV)绑定大量的数据 - 如STL容器。 – user2311165