要在自己定义类型中使用移动算法。须要在元素中提供移动赋值运算符。移动赋值运算符和std::move()详见《c++高级编程》第9章

class mystring
{
public:
string mstr; mystring(){}
mystring(const string &str) :mstr(str){} mystring& operator=(mystring&& rhs)//<span style="font-size:18px;">移动赋值运算符</span>
{
if (this == &rhs)
return *this;
mstr = std::move(rhs.mstr);
return *this;
}
};

主函数:

vector<int> n = {-3,9,-6,3,8,7 };
vector<mystring> sfrom = { mystring("a"), mystring("b"), mystring("c") }; vector<mystring> sto(3);
move(sfrom.begin(), sfrom.end(), sto.begin());//<span style="font-size:18px;">移动算法</span>
for (auto &t : sto)
cout << t.mstr << "\t";
cout << endl; for (auto &t : sfrom)
cout << t.mstr << "\t";
cout << endl;

最新文章

  1. Java多线程系列--“基础篇”01之 基本概念
  2. 剑指Offer 链表中倒数第k个结点
  3. Sprint Three 回顾与总结&amp;发表评论&amp;团队贡献分
  4. C#5.0 .net 4.5示例
  5. GCD 多线程同步
  6. sublime text2支持ng
  7. hdu 4632 动态规划
  8. HeadFirst设计模式之装饰者模式
  9. 可以使用Markdown了?
  10. 【制作镜像Win*】系统安装
  11. &amp;quot;蓝筹&amp;quot;如何使程序猿?
  12. 在android中如何查看sqlite数据表结构,以及data文件打不开问题
  13. poj 3273 Monthly Expense(二分搜索之最大化最小值)
  14. codevs 1455 路径 计算m^n%p
  15. Cocos2d-x3.2游戏的核心循环在Application,怎样处理FPS不稳
  16. Zookeeper 集群安装
  17. MTK6577+Android之Camera驱动
  18. mybatis关于ORM的使用以及设计(三)[参数对象转换为SQL语言]
  19. opencv: 基本知识;
  20. VideoView 监听视频格式不支持时的错误。

热门文章

  1. Zepto,Zepto API 中文版,Zepto 中文手册,Zepto API,Zepto API 中文版,Zepto 中文手册,Zepto API 1.0, Zepto API 1.0 中文版,Zepto 1.0 中文手册,Zepto 1.0 API-translate by yaotaiyang
  2. word2vec 入门(三)模型介绍
  3. [置顶] Ajax核心--XMLHttpRequest对象
  4. 个人VIM配置文件
  5. 加濾鏡效果GlowTween
  6. jQuery--checkbox全选/取消全选
  7. select Into用法
  8. Struts2 访问web元素
  9. linux下Java环境的配置
  10. C# 3循环 for语句应用