STL 源码分析 # stl_number #
来源:互联网 发布:淘宝一千多的硅胶娃娃 编辑:程序博客网 时间:2024/04/29 16:44
STL 源码分析 # stl_number #
/***********************************************************Programmer:EOFe-mail:jasonleaster@gmail.comDate:2015.04.04File:6number.cpp************************************************************/#include <numeric>#include <vector>#include <functional>#include <iostream>#include <iterator>using namespace std;int main(int argc, char const *argv[]){int ia[5] = {1,2,3,4,5};vector<int> iv(ia, ia + 5);cout << accumulate(iv.begin(), iv.end(), 0) << endl;cout << accumulate(iv.begin(), iv.end(), 0, minus<int>() ) << endl;cout << inner_product(iv.begin(), iv.end(), iv.begin(), 10) << endl;cout << inner_product(iv.begin(), iv.end(), iv.begin(), 10, minus<int>(), plus<int>()) << endl;ostream_iterator<int> oite(cout, " ");partial_sum(iv.begin(), iv.end(), oite);partial_sum(iv.begin(), iv.end(), oite, minus<int>());adjacent_difference(iv.begin(), iv.end(), oite);adjacent_difference(iv.begin(), iv.end(), oite, plus<int>());for(int i = 0; i < iv.size(); i++){cout << iv.at(i) << " ";}cout << endl;return 0;}
accumulate()的实现
内积 inner_product()
/
partial_sum()和之前的accumulate()不一样,partial_sum()可能会把一步步积分的结果粗村在__result指向的
"连续数据结构内".之所以这么说,是因为,这货可能是数组,也可能是其他支持++运算符迭代器的类型.
把相邻的数据做差分,然后储存在__result指向的数据结构内
power()的实现.不过话说我主机里面的STL 还没有支持power...不能用.
0 0
- STL 源码分析 # stl_number #
- stl源码分析请教
- [STL]源码分析:allocator
- STL hashtable 源码分析
- STL源码分析--list
- STL源码分析--deque
- STL源码分析--算法
- STL源码分析 # vector #
- STL 源码分析 # stl_pair #
- C++ STL 源码分析
- STL源码分析(总结)
- STL源码分析set
- STL源码分析
- STL vector源码分析
- STL源码分析之感想
- STL源码分析之Vector
- STL 中sort源码分析
- 阅读《STL源码分析》有感
- leetcode - Insert Interval
- https原理
- 使用JS对form的内容验证失败后阻止提交
- Unity3d linux版本如果做Splash屏幕
- 汽车加油
- STL 源码分析 # stl_number #
- java集合框架List之ArrayList(二)
- Collection与Map
- Android侧滑菜单DrawerLayout
- LeetCode 53/152 Maximum Subarray/Maximum Product Subarray---DP **
- python取两个list的交集并集差集
- 安装JDK不当--找不到或无法加载主类 com.sun.tools.javac.Main
- Objective-C使用form方式提交json
- 中文数字转换成阿拉伯数字(一千二百三十四万五千六百七十八-->12345678)