【发布时间】:2016-10-26 03:25:26
【问题描述】:
将元素从某种类型 (T1) 的向量 std::move 到具有相同类型 (T1) 和另一种类型 (T2) 的 std::pair 向量中的最正确和最有效的方法是什么?
也就是说,我应该怎么写MoveItems()?
#include <iostream> // For std::string
#include <string> // For std::string
#include <vector> // For std::vector
#include <utility> // For std::pair
using std::vector;
using std::string;
using std::pair;
vector<string> DownloadedItems;
vector<pair<string,bool>> ActiveItems;
vector<string> Download()
{
vector<string> Items {"These","Words","Are","Usually","Downloaded"};
return Items;
}
void MoveItems()
{
for ( size_t i = 0; i < DownloadedItems.size(); ++i )
ActiveItems.push_back( std::pair<string,bool>(DownloadedItems.at(i),true) );
}
int main()
{
DownloadedItems = Download();
MoveItems();
return 0;
}
感谢您的时间和帮助,我真的很感激!
【问题讨论】:
标签: c++ vector move-semantics universal-reference