cplusplus系列>algorithm>std::for_each】的更多相关文章

http://www.cplusplus.com/reference/algorithm/for_each/ 对一个序列应用函数.可以是函数指针,或者是functor. // for_each example #include <iostream> // std::cout #include <algorithm> // std::for_each #include <vector> // std::vector void myfunction (int i) { //…
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commented lines, excution time increase to 15ms from 0ms, due to worse locality? thanks to http://acm.hdu.edu.cn/discuss/problem/post/reply.php?action=support…
std::fill 在[first, last)范围内填充值 #include <iostream> #include <vector> #include <algorithm> int main() { std::vector<int> v; v.resize(); std::fill(v.begin(), v.end(), ); ; } std::fill_n 在[fist, fist + count)范围内填充值 #include <iostre…
std::find: 查找容器元素, find仅仅能查找容器元素为<基本数据类型> [cpp] view plaincopy #include <iostream> #include <vector> #include <algorithm> int main() { std::vector<int> v; for (int i = 0; i < 10; ++i) v.push_back(i); std::vector<int>…
简介 algorithm头文件是C++的标准算法库,它主要应用在容器上. 因为所有的算法都是通过迭代器进行操作的,所以算法的运算实际上是和具体的数据结构相分离的 ,也就是说,具有低耦合性. 因此,任何数据结构都能使用这套算法库,只要它具有相应的迭代器类型. 算法类别 如上图所示,库中的算法主要分为4类: 非修改性顺序操作(Non-modifying sequence operations) 可变顺序操作(Mutating sequence operations) 排序和关系操作(Sorting…
http://www.cplusplus.com/reference/utility/pair/ 用于存储一对异构对象 // Compile: g++ -std=c++11 pair.cpp #include <utility> #include <string> #include <iostream> #include <tuple> int main () { std::pair <std::string, int> p1; // defau…
http://www.cplusplus.com/reference/algorithm/for_each/ template<class InputIterator, class Function> Function for_each(InputIterator first, InputIterator last, Function fn) { while (first!=last) { fn (*first); ++first; } return fn; // or, since C++1…
概述:不变序列算法,参见http://www.cplusplus.com/reference/algorithm/ /* std::for_each template <class InputIterator, class Function> Function for_each (InputIterator first, InputIterator last, Function fn); Apply function to range Applies function fn to each o…
http://www.cplusplus.com/reference/algorithm/for_each/ std::move()用于c++11 http://www.cplusplus.com/reference/utility/move/ c++98 // for_each example #include <iostream> // std::cout #include <algorithm> // std::for_each #include <vector>…
template<class InputIterator> typename iterator_traits<InputIterator>::difference_type distance (InputIterator first, InputIterator last); Return distance between iterators Calculates the number of elements between first and last. // advance e…