使用adjacent_difference要注意的小问题
2015-12-08 19:12
316 查看
adjacent_difference的源与目的地可以相同,这是在标准中说明的,所以我产生了疑问,会不会因为这样使用而改变了当前成员,而影响下一步计算呢,经试验,在vs2015里并不会。
输出:
1 2 3 4 5 6
1 3 5 7 9 11
1 3 5 7 9 11
看来并无影响。
在侯捷先生的STL源码剖析和cppreference中都有提到会生成临时变量存储前一个元素以备下一次使用,看来我们可以放心用了。
#include "stdafx.h" #include "algostuff.hpp" using namespace std; int main() { deque<int> coll; INSERT_ELEMENTS(coll, 1, 6); PRINT_ELEMENTS(coll); // print all sums with the predecessors adjacent_difference(coll.cbegin(), coll.cend(), // source ostream_iterator<int>(cout, " "), // destination plus<int>()); // operation cout << endl; // print all sums with the predecessors to the source adjacent_difference(coll.cbegin(), coll.cend(), // source coll.begin(), // destination plus<int>()); PRINT_ELEMENTS(coll); cout << endl; return 0; }
输出:
1 2 3 4 5 6
1 3 5 7 9 11
1 3 5 7 9 11
看来并无影响。
在侯捷先生的STL源码剖析和cppreference中都有提到会生成临时变量存储前一个元素以备下一次使用,看来我们可以放心用了。
相关文章推荐
- 浅谈AngularJS的$parse服务 这篇可以让你看明白
- Fiddler进行模拟Post提交json数据,总为null解决方式
- 15个值得开发人员关注的jQuery开发技巧和心得
- css3画三角形的原理
- node.js 入门笔记
- css3之background-clip
- 模拟上传头像支持截图
- css中的line-height小知识
- web自动化(5)----selenium运行JavaScript代码
- AngularJs的简单理解和案例
- html5 jqueryrotate插件实现旋转动画
- html5 jqueryrotate插件实现旋转动画
- html5 jqueryrotate插件实现旋转动画
- Angular的侦察兵:$watch()和$observe()
- Dojo Deferreds and Promises
- js中我使用hover事件当处于这个div上时显示,离开时慢慢消失,研究了很久,最后发现添加了return就可以了
- js 检测浏览器,呈现引擎和平台
- ReactiveCocoa 编程框架学习(一)
- 将json 数组转换为Map 对象;为[{},{},{}]此类字; 则返回每个{}对象的map;
- 将json 数组转换为Map 对象;[{}]此类字符串 则返回的对象的map