Effective Modern C++学习总结

C++11/14的发布是C++发展的里程碑,成为了现代的编程语言。和Java8一样,极大丰富了语言的能力,更加高效的利用CPU及硬件的性能。最近读了经典书籍《Effective Modern C++》,在此总结一下。书中源代码可以参考

https://github.com/BartVandewoestyne/Effective-Modern-Cpp 

 

1 型别推导,包括auto/decltype;

2 空指针nullptr,取代了老的不好用的0和NULL;

3 优先选用别名声明using,而非typedef;

4 智能指针升级:unique_ptr/ shared_ptr / weak_ptr;有力的避免了内存泄漏的问题;

5 针对右值引用实施std::move,针对万能引用实施std::forward;避免了无谓的复制,有效的提高了性能;

6 优先选用lambda表达式,而非std::bind;

7 全新的跨平台的并发API,使用std::thread/ std::async进行多线程开发;对并发使用std::atomic,对特殊内存使用volatile;

8 增加了可变参数模板,使得泛型编程能力更加强大,大幅消除了重复模板定义;

9 C++过去仅仅支持类模板可以有默认的模板参数;C++11现在支持函数的默认模板参数;

10 C++中,初始化列表的适用性被大大的增加了;

其中的lambda表达式,for-loop循环,tuple,初始化列表等特性和Java8等高级语言相似,使得学习编写C++程序更加简洁和顺手。而且各种语言通学通用,相互比较,融汇贯通。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Coming to grips with C++11 and C++14 is more than a matter of familiarizing yourself with the features they introduce (e.g., auto type declarations, move semantics, lambda expressions, and concurrency support). The challenge is learning to use those features effectively—so that your software is correct, efficient, maintainable, and portable. That’s where this practical book comes in. It describes how to write truly great software using C++11 and C++14—i.e. using modern C++. Topics include: The pros and cons of braced initialization, noexcept specifications, perfect forwarding, and smart pointer make functions The relationships among std::move, std::forward, rvalue references, and universal references Techniques for writing clear, correct, effective lambda expressions How std::atomic differs from volatile, how each should be used, and how they relate to C++'s concurrency API How best practices in "old" C++ programming (i.e., C++98) require revision for software development in modern C++ Effective Modern C++ follows the proven guideline-based, example-driven format of Scott Meyers' earlier books, but covers entirely new material. "After I learned the C++ basics, I then learned how to use C++ in production code from Meyer's series of Effective C++ books. Effective Modern C++ is the most important how-to book for advice on key guidelines, styles, and idioms to use modern C++ effectively and well. Don't own it yet? Buy this one. Now". -- Herb Sutter, Chair of ISO C++ Standards Committee and C++ Software Architect at Microsoft
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值