STL的移动算法
2024-10-14 06:48:48
要在自己定义类型中使用移动算法。须要在元素中提供移动赋值运算符。移动赋值运算符和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;
最新文章
- Java多线程系列--“基础篇”01之 基本概念
- 剑指Offer 链表中倒数第k个结点
- Sprint Three 回顾与总结&;发表评论&;团队贡献分
- C#5.0 .net 4.5示例
- GCD 多线程同步
- sublime text2支持ng
- hdu 4632 动态规划
- HeadFirst设计模式之装饰者模式
- 可以使用Markdown了?
- 【制作镜像Win*】系统安装
- &;quot;蓝筹&;quot;如何使程序猿?
- 在android中如何查看sqlite数据表结构,以及data文件打不开问题
- poj 3273 Monthly Expense(二分搜索之最大化最小值)
- codevs 1455 路径 计算m^n%p
- Cocos2d-x3.2游戏的核心循环在Application,怎样处理FPS不稳
- Zookeeper 集群安装
- MTK6577+Android之Camera驱动
- mybatis关于ORM的使用以及设计(三)[参数对象转换为SQL语言]
- opencv: 基本知识;
- VideoView 监听视频格式不支持时的错误。
热门文章
- 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
- word2vec 入门(三)模型介绍
- [置顶] Ajax核心--XMLHttpRequest对象
- 个人VIM配置文件
- 加濾鏡效果GlowTween
- jQuery--checkbox全选/取消全选
- select Into用法
- Struts2 访问web元素
- linux下Java环境的配置
- C# 3循环 for语句应用