stl 学习笔记 8 续 (function object)
2007-11-28 11:48
369 查看
function object 续
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//stl/fo1.cpp
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
预先定义好的 function object
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <set>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <deque>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <algorithm>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "print.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
set<int,greater<int> > coll1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
deque<int> coll2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i = 1; i<=9;++i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
coll1.insert(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll1,"initialized: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// bind2nd
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// function adaptors
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
transform(coll1.begin(),coll1.end(),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
back_inserter(coll2),bind2nd(multiplies<int>(),10));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll2,"transformed: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// replace_if (algorithm)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
replace_if(coll2.begin(),coll2.end(),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
bind2nd(equal_to<int>(),70),42);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll2,"replaced: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
coll2.erase(remove_if(coll2.begin(),coll2.end(),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
bind2nd(less<int>(),50)),coll2.end());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// less<> function object
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll2,"removed: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//stl/fo1.cpp
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
预先定义好的 function object
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <set>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <deque>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <algorithm>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "print.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
set<int,greater<int> > coll1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
deque<int> coll2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i = 1; i<=9;++i)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
coll1.insert(i);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll1,"initialized: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// bind2nd
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// function adaptors
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
transform(coll1.begin(),coll1.end(),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
back_inserter(coll2),bind2nd(multiplies<int>(),10));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll2,"transformed: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// replace_if (algorithm)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
replace_if(coll2.begin(),coll2.end(),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
bind2nd(equal_to<int>(),70),42);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll2,"replaced: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
coll2.erase(remove_if(coll2.begin(),coll2.end(),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
bind2nd(less<int>(),50)),coll2.end());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// less<> function object
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
PRINT_ELEMENTS(coll2,"removed: ");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- C++ STL 学习笔记 vector
- 标准模板库(STL)学习笔记之List容器
- C++ STL 学习笔记 string
- C++标准程序库 学习笔记 第五章 STL(标准模板库概述)
- 【学习笔记】C++高级程序设计:STL标准模板库
- PKU C++程序设计实习 学习笔记6 标准模板库STL
- STL学习笔记-入门概念
- STL学习笔记-deque容器(双端动态数组)
- C++ Primer Plus学习笔记之STL容器
- STL学习笔记之容器--deque(一)
- STL学习笔记之容器--优先队列
- STL学习笔记之容器--string
- STL学习笔记----5.容器 set 和 multiset
- STL 基本入门笔记学习
- STL学习笔记之容器--list(一)
- STL学习笔记6 -- 栈stack 、队列queue 和优先级priority_queue 三者比较
- C++ Primer 学习笔记_41_STL实践与分析(15)--先来看看算法【下一个】
- C++ Primer 学习笔记_36_STL实践与分析(10)--map类型(下
- C++ Primer 学习笔记_44_STL实践与分析(18)--再谈迭代器【下】
- STL学习笔记---- iterator