用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧Visual C++

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

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 20:27:05

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.
         [知道一些,还不令我满意]


 


Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:29,234.38000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号