Effective STL 学习笔记:19 ~ 20
Effective STL 学习笔记:19 ~ 20
*/-->
div.org-src-container {
font-size: 85%;
font-family: monospace;
}
Table of Contents
1 Item 19: 相等 (Equality) 与等价 (Equivalence)
在 STL 中, 相等 (Equality) 用于 find 算法中,通常通过 \(operator ==\) 来体现。而 等价
(Equivalence) 则经常用于排序,通常用 \(operator
\begin{cases}
& !(w1
2 Item 20: Specify Comparison Type for Associative containers of pointers
对于存放指针的 Associative Containers 而言,如果我们不指定排序算法,则默认按照 指针 大小去排,对象指针我们无法控制,他们在容器中的排列顺序我们也就无法控制。如果我们需要指定其排序顺序,需自己指定 Comparison Type,例如:
class StrLessFunctor
{
public:
StrLessFunctor(){}
virtual ~StrLessFunctor(){}
bool operator()(const string* ps1, const string* ps2)
{
return *ps1 < *ps2;
}
}; int main(int argc, char *argv[])
{
set<string*, StrLessFunctor> ssp;
ssp.insert(new string("Banana"));
ssp.insert(new string("Orange"));
ssp.insert(new string("Apple")); for_each(ssp.begin(), ssp.end(), [](string* s){cout << *s << endl;});
return 0;
}
构造 set 时候指定的第二个模板参试不是一个函数,而是一个类型 (Comparison Type), set 会用该类型来初始化出来一个用于 sort 的函数。
(使用许可:署名-非商业性使用-相同方式共享 3.0 中国大陆许可协议 。)
Effective STL 学习笔记:19 ~ 20的更多相关文章
- Effective STL 学习笔记 32 ~ 33
Effective STL 学习笔记 32 ~ 33 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...
- Effective STL 学习笔记 31:排序算法
Effective STL 学习笔记 31:排序算法 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...
- Effective STL 学习笔记: Item 22 ~ 24
Effective STL 学习笔记: Item 22 ~ 24 */--> div.org-src-container { font-size: 85%; font-family: monos ...
- Effective STL 学习笔记 39 ~ 41
Effective STL 学习笔记 39 ~ 41 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...
- Effective STL 学习笔记 Item 38 : Design functor classes for pass-by-value
Effective STL 学习笔记 Item 38 : Design functor classes for pass-by-value */--> div.org-src-container ...
- Effective STL 学习笔记 Item 34: 了解哪些算法希望输入有序数据
Effective STL 学习笔记 Item 34: 了解哪些算法希望输入有序数据 */--> div.org-src-container { font-size: 85%; font-fam ...
- Effective STL 学习笔记 Item 30: 保证目标区间足够大
Effective STL 学习笔记 Item 30: 保证目标区间足够大 */--> div.org-src-container { font-size: 85%; font-family: ...
- Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor
Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor */--> div ...
- Effective STL 学习笔记 Item 21:Comparison Function 相关
Effective STL 学习笔记 Item 21:Comparison Function 相关 */--> div.org-src-container { font-size: 85%; f ...
随机推荐
- windows配置Python多版本共存
windows配置Python多版本共存 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 最近Python开发蛮火的,三年前我的一个运维朋友就告诉我说Python语言将来会很火,当时 ...
- logstash定义表达式
例如: echo '[2018/02/02 08:34:43.032]' >> tomcat_catalina.out 过滤方式 "message" => &qu ...
- bzoj千题计划151:bzoj1131: [POI2008]Sta
http://www.lydsy.com/JudgeOnline/problem.php?id=1131 dp[i]=dp[fa[i]]-son[i]+n-son[i] #include<cst ...
- Training Neural Networks: Q&A with Ian Goodfellow, Google
Training Neural Networks: Q&A with Ian Goodfellow, Google Neural networks require considerable t ...
- 取消IE下的叉
之前写项目的时候碰到一个小问题,因为IE下的那个叉触发不了我的change事件,所以只好把IE给加上去的那个叉去了,在此记录一下. ::-ms-clear{display:none;} ::-ms-r ...
- JQuery的选择器对控件ID含有特殊字符的解决方法-涨姿势了!
1.jquery类库在我们实际项目中用的很多,大家经常需要根据控件的id,获取对应的html元素. 但是:当id含有特殊字符的时候,是不能选中的. 2. 自己简单的测试了下,jquery的id选择器只 ...
- CodeForces - 1040B Shashlik Cooking
Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simu ...
- Oracle错误: ORA-01722 无效数字
ORA-01722: 无效数字 主要原因是: 1.对于两个类型不匹配(一个数字类型,一个非数字类型,同下)的值进行赋值操作; 2.两个类型不匹配的值进行比较操作(例如,"="); ...
- sklearn_k邻近分类
# K邻近分类#--------------------------------# coding:utf-8 import pandas as pd from sklearn.neighbors im ...
- [转]双线性插值(Bilinear interpolation)
1,原理 在图像的仿射变换中,很多地方需要用到插值运算,常见的插值运算包括最邻近插值,双线性插值,双三次插值,兰索思插值等方法,OpenCV提供了很多方法,其中,双线性插值由于折中的插值效果和运算速度 ...