Effective C++ 3nd 读书摘要(九、杂项讨论)Item53 - 55
2009-06-01 17:42
561 查看
九、杂项讨论
Item53. 不要轻忽编译器的警告
比如:
编译器会警告:
warning: D::f() hides virtual B::f()
因为D中的f()没有const。
Item54. 让自己熟悉包括TR1在内的标准程序库
TR1组件有:
1. The smart pointers TR1::shared_ptr 和 tr1::weak_ptr. TR1::shared_ptrs
2. tr1::function(Item35)
3. tr1::bind(Item35)
其他TR1组件划分为两组:
①Hash tables、Regular expressions、Tuples、tr1::array、tr1::mem_fn、tr1::reference_wrapper、Random number generation、Mathematical special functions、C99 compatibility extension
②Type traits、tr1::result_of
简单示范:
①tr1::function
ITem55. 让自己熟悉Boost(http://boost.org)
Boost程序库的主题主要有:
String and text processing、Containers、Function objects and higher-order programming、Generic programming、Template metaprogramming(TMP)、Math and numerics、Correctness and testing、Data structures、Inter-language support、Memory、Miscellaneous
简单示范:
①Function objects and higher-order programming
②Template metaprogramming(TMP)
Item53. 不要轻忽编译器的警告
比如:
class B { public: virtual void f() const; }; class D: public B { public: virtual void f(); };
编译器会警告:
warning: D::f() hides virtual B::f()
因为D中的f()没有const。
Item54. 让自己熟悉包括TR1在内的标准程序库
TR1组件有:
1. The smart pointers TR1::shared_ptr 和 tr1::weak_ptr. TR1::shared_ptrs
2. tr1::function(Item35)
3. tr1::bind(Item35)
其他TR1组件划分为两组:
①Hash tables、Regular expressions、Tuples、tr1::array、tr1::mem_fn、tr1::reference_wrapper、Random number generation、Mathematical special functions、C99 compatibility extension
②Type traits、tr1::result_of
简单示范:
①tr1::function
void registerCallback(std::tr1::function<std::string (int)> func); // the param "func" will take any callable entity // with a sig consistent with "std::string (int)"
ITem55. 让自己熟悉Boost(http://boost.org)
Boost程序库的主题主要有:
String and text processing、Containers、Function objects and higher-order programming、Generic programming、Template metaprogramming(TMP)、Math and numerics、Correctness and testing、Data structures、Inter-language support、Memory、Miscellaneous
简单示范:
①Function objects and higher-order programming
using namespace boost::lambda; // make boost::lambda functionality visible std::vector<int> v; ... std::for_each(v.begin(), v.end(), // for each element x in std::cout << _1 * 2 + 10 << "/n"); // v, print x*2+10; // "_1" is the Lambda library's placeholder for the current element
②Template metaprogramming(TMP)
// create a list-like compile-time container of three types (float, // double, and long double) and call the container "floats" typedef boost::mpl::list<float, double, long double> floats; // create a new compile-time list of types consisting of the types in // "floats" plus "int" inserted at the front; call the new container "types" typedef boost::mpl::push_front<floats, int>::type types;
相关文章推荐
- Effective C++ 3nd 读书摘要(三、资源管理 ;四、设计与声明;五、实现)Item13 - 31
- Effective C++ 3nd 读书摘要(六、继承与面向对象设计)Item32 - 40
- Effective C++ 3nd 读书摘要(一、让自己习惯C++ ; 二、构造,析构,赋值运算)Item1 - 12
- More Effective C++ 读书摘要(六、杂项)Item32 - 35
- Effective C++ 3nd 读书摘要(七、模板与泛型编程)Item41 - 48
- Effective C++ 3nd 读书摘要(八、定制new和delete)Item49 - 52
- Effective C++ 3nd 读书摘要(Third Edition 55 Specific Ways to Improve Your Programs and Design)
- 《Effective C++》读书笔记之item55:让自己熟悉Boost
- Effective C++ 笔记 第九部分 杂项讨论
- More Effective C++ 读书摘要(一、基础议题 二、运算符)Item1 - 8
- Effective C++ 读书笔记(45-50):杂项讨论
- 《Effective C++》读书笔记之item53:不要轻忽编译器的警告
- effective C++: 9.杂项讨论
- More Effective C++ 读书摘要(五、技巧2)Item28 - 29
- Effective C++ —— 杂项讨论(九)
- More Effective C++ 读书摘要(五、技巧1)Item25 - 27
- More Effective C++ 读书摘要(三、异常)Item9 - 15
- Effective C++(九)杂项讨论
- Effective c++ 9 53...55
- More Effective C++ 读书摘要(四、效率)Item16 - 24