for_each 用法!】的更多相关文章

匿名函数,C++11的 for_each 用法 #include <iostream> #include <algorithm> #include "testClassA.h" using namespace std; void tiwce(int& elem) { elem = elem * ; } // 不带参数,不带返回值 // [](){cout << 123 << ","; }; // []{cout…
class MapTest:public CapTest{ private: set <string> MyTestContain; typedef pair <string,int> myPairDef; typedef map <string,int> myMapDef; myMapDef MyMap1; public: MapTest(); ~MapTest(){}; void OutPut(); friend void MyOutPut2(myPairDef t…
for_each()是个function template #include <algorithm>头文件说明 template<class _InIt, class _Fn1> inline void _For_each(_InIt _First, _InIt _Last, _Fn1& _Func) { // perform function for each element for (; _First != _Last; ++_First) _Func(*_First)…
STL的概念 源地址  https://www.ev0l.art/index.php/archives/15/ <li> Iterator (迭代器)<li> Container (容器) array<li> Alogrithm (算法)<li> Adapters (配接器) 用来实现容器之间的转接 面向过程-->面向对象->基于对象->泛型 代码 #include <iostream> #include <vector&…
不学STL,无以立.--陈轶阳 从1.1节到1.8节大部分都是从各方面介绍STL, 包括历史之类的(大致上是这样,因为实在看不下去我就直接略到了1.9节(其实还有一点1.8.3的内容)). 第一章里比较实用(能用在自己代码当中)的部分应该就是1.9节可能令你困惑的C++语法这部分了. 而1.9中又分为以下几个小节: 1.9.1 stl_config.h 中的各种组态(configurations) 1.9.2 临时对象的产生和运用 1.9.3 静态常量整数成员在class 内部直接初始化 1.9…
看到手册的代码里面有个for的很奇怪的用法,用了一把    http://www.cplusplus.com/reference/unordered_set/unordered_set/insert/ 编译  g++ -o test main.cpp -std=c++11…
C++使用如下方法遍历一个容器: #include "stdafx.h" #include<iostream> #include<vector> int main() { std::vector<int> arr; arr.push_back(); arr.push_back(); for (auto it = arr.begin(); it != arr.end(); it++) { std::cout << *it <<…
STL vector用法介绍 介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通过阅读这篇文章读者应该能够有效地使用vector容器,而且应该不会再去使用C类型的动态数组了.   Vector总览 vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector之所以被认为是一个容器,是因为它能…
std::bind1st 和 std::bind2nd将二元函数转换为一元函数,具体用法参加下面的代码. 代码介绍了两种使用方式,第一种是使用std::less和std::greater,第二种是使用自定义的仿函数. #include <iostream> #include <vector> #include <string> #include <iterator> #include <algorithm> #include <functi…
1 , accumulate()template<class _II, class _Ty> inline_Ty accumulate(_II _F, _II _L, _Ty _V){for (; _F != _L; ++_F)_V = _V + *_F;return (_V); }作用就是计算累积.2,adjacent_difference()_OI _Adjacent_difference(_II _F, _II _L, _OI _X, _Ty *){_Ty _V = *_F;for (*…