分享
 
 
 

Scott Meyers的新书 Effective STL: 提高STL使用技术的50招

王朝vc·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Effective C++/More Effective C++的作者Scott Meyers即将推出最新力作:Effective STL, 该书目前已经完成,相信不久可以问世。但是与中国读者见面恐怕还是要在苦等之后。Addison=Wesley已经刊出了此书的页面。地址http://cseng.aw.com/book/toc/0,3830,0201749629,00.html

下面是该书的内容:

某些条款我基本可以理解,大部分知道应该如此,但不知其所以然,某些条款令我相当诧异,所以更希望能够早日拜读。我对于某些条款的感想用[]写在下面,我相信也是Meyers书中能够解释的东西。如果对于STL感兴趣的网友能够就这些条款展开讨论,我相信是非常有帮助的。

1. Containers

Item 1: Choose your containers with care.

Item 2: Beware the illusion of container-independent code.

[值得注意的条款!]

Item 3: Make copying cheap and correct for objects in containers.

[可以理解,可是如何做到cheap,哪些情况下容易作出不正确的copy操作?]

Item 4: Call empty instead of checking size against zero.

[何故?]

Item 5: Prefer range member functions to their single-element counterparts.

[何故?]

Item 6: Be alert for C++'s most vexing parse.

[谈何容易!]

Item 7: When using containers of newed pointers, remember to delete the pointers before the container is destroyed.

[可以理解]

Item 8: Never create containers of auto_ptrs.

[可以理解]

Item 9: Choose carefully among erasing options.

[非常令我感兴趣的条款]

Item 10: Be aware of allocator conventions and restrictions.

[好深入的话题!]

Item 11: Understand the legitimate uses of custom allocators.

[怎么做?我略知一二,希望强化这方面的知识]

Item 12: Have realistic expectations about the thread safety of STL containers.

[呵呵,重要条款]

2. Vector and string.

Item 13: Prefer vector and string to dynamically allocated arrays.

[对了,basic_string本身就是一个动态数组容器,大家别以为只有vector]

Item 14: Use reserve to avoid unnecessary reallocations.

[太对了,vector一旦发现容量(capacity)不足,会以惊人的魄力re-allocate,

要当心,不然很惨]

Item 15: Be aware of variations in string implementations.

[愿洗耳恭听]

Item 16: Know how to pass vector and string data to legacy APIs.

[Viva! I know a little bit about that..., but wait a minute, 根据我看

Effective C++的经验,千万别以为你知道不少,Meyers会狠狠教训你,让你知道

什么叫做井观天]

Item 17: Use "the swap trick" to trim excess capacity.

[哈,我一点都不懂!]

Item 18: Avoid using vector.

[惊诧!完全打击!我一直把vector当首选容器!Meyers,我希望你给我个

不用vector的理由先]

3. Associative Containers.

Item 19: Understand the difference between equality and equivalence.

[戳到死穴,真的不知道两者有何不同,马上查书去]

Item 20: Specify comparison types for associative containers of pointers.

[嗯,有道理!]

Item 21: Always have comparison functions return false for equal values.

[啊?又一个晴天霹雳!简直匪夷所思嘛!不过想想,啊,Meyers真伟大]

Item 22: Avoid in-place key modification in set and multiset.

[不好意思,从来没正儿八经用过set]

Item 23: Consider replacing associative containers with sorted vectors.

[好建议!]

Item 24: Prefer map::insert to map::operator[] when efficiency is a concern.

[嘿嘿,虽然没仔细想过这个问题,但是我可是一直都使用insert的哟!道理吗, 好想知道那么一点点,不过还是谨慎点好,我怕Meyers又来敲我的头...]

Item 25: Familiarize yourself with the nonstandard hashed containers.

[弱点!我还是快去补补课吧!]

4. Iterators.

Item 26: Prefer iterator to const_iterator, reverse_iterator, and const_reverse_iterator.

[晴天霹雳3!不是说要尽可能地用const吗,怎么加了个下划线就不认帐了?不行, 您得给我讲清楚...]

Item 27: Use distance and advance to convert const_iterators to iterators.

[丈二和尚]

Item 28: Understand how to use a reverse_iterator's base iterator.

[更是连概念都搞不清楚了,reverse_iterator还有base iterator? 赶快去查查书]

Item 29: Consider istreambuf_iterators for character by character input.

[唔,值得好好研究]

5. Algorithms.

Item 30: Make sure destination ranges are big enough.

[应该是可以理解的吧!]

Item 31: Know your sorting options.

[原则上理解]

Item 32: Follow remove-like algorithms by erase if you really want to remove something.

[呵呵,又可以理解!]

Item 33: Be wary of remove-like algorithms on containers of pointers.

[好险!这确实是个需要警惕的问题]

Item 34: Note which algorithms expect sorted ranges.

[不太清楚...]

Item 35: Implement simple case-insensitive string comparisons via mismatch or lexicographical_compare.

[不太清楚...]

Item 36: Use not1 and remove_copy_if to perform a copy_if.

[以前在comp.lang.c++.moderated上读到过关于这个条款的故事,很精彩的!Scott Meyers 和Matt Austern都在这个问题上不小心栽了跟头,最后还是Bjarne Stroustrup一锤定音。等毕业论文改完了讲给大家听。]

Item 37: Use accumulate or for_each to summarize sequences

[谨遵师命]

6. Functors, Functor Classes, Functions, etc.

Item 38: Design functor classes for pass-by-value.

[概念上有点糊涂]

Item 39: Make predicates pure functions.

[晴天霹雳4,Stroustrup不是说Functor可以产生更高效的inline代码吗?为什么predications要例外呢? 俺要个说法。]

Item 40: Make functor classes adaptable.

[这个问题跟条款36相关的,看来Meyers真的从copy_if的教训中挖掘出不少宝藏]

Item 41: Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref.

[表面上是know了,但是老也想不起用它们来,说明还没有understand]

Item 42: Make sure less means operator<.

[从来没想到过这个问题有什么重要性]

7. Programming with the STL.

Item 43: Prefer algorithm calls to hand-written loops.

[我虽然从来都是如此这般作,却不知出了使自己的代码看起来更须cool以外还有什么别的道理]

Item 44: Prefer member functions to algorithms with the same names.

[算不上是晴天霹雳,但也很出乎我的意料,我一直以用纯algorithms操作contain为荣]

Item 45: Distinguish among count, find, binary_search, lower_bound, upper_bound, and equal_range.

[好像略知一二]

Item 46: Consider function objects instead of functions as algorithm parameters.

[这跟条款39不矛盾吗?]

Item 47: Avoid producing write-only code.

[不懂]

Item 48: Always #include the proper headers.

Item 49: Learn to decipher STL-related compiler diagnostics.

[谈何容易,尤其是VC]

Item 50: Familiarize yourself with STL-related web sites.

[知道一些,还不令我满意]

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有