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