c++
A Tour of C++ 豆瓣
作者: Bjarne Stroustrup Addison-Wesley Professional; 3rd edition (October 10, 2022) 2022 - 10
In A Tour of C++, Third Edition, Bjarne Stroustrup provides an overview of ISO C++, C++20, that aims to give experienced programmers a clear understanding of what constitutes modern C++. Featuring carefully crafted examples and practical help in getting started, this revised and updated edition concisely covers most major language features and the major standard-library components needed for effective use.

Stroustrup presents C++ features in the context of the programming styles they support, such as object-oriented and generic programming. His tour is remarkably comprehensive. Coverage begins with the basics, then ranges widely through more advanced topics, emphasizing newer language features. This edition covers many features that are new in C++20 as implemented by major C++ suppliers, including modules, concepts, coroutines, and ranges. It even introduces some library components in current use that are not scheduled for inclusion in the standard until C++23.

This authoritative guide does not aim to teach you how to program (for that, see Stroustrup's Programming: Principles and Practice Using C++, Second Edition), nor will it be the only resource you'll need for C++ mastery (for that, see Stroustrup's The C++ Programming Language, Fourth Edition, and recommended online sources). If, however, you are a C or C++ programmer wanting greater familiarity with the current C++ language, or a programmer versed in another language wishing to gain an accurate picture of the nature and benefits of modern C++, you won't find a shorter or simpler introduction.
2024年9月14日 已读
2022年11月12日 评论 C++ 为什么难? - A Tour of C++ 在二〇二二年十月终于出第三版了,已更新到 C++20 并有若干 C++23 内容。内容简洁,是给有编程经验的读者看的。通过这书我彻底理解了 object,variable,initialization,value 等的定义,也明白了 declaration,definition 和 initialization 之间的微妙关系,真是大道至简。 虽然这书很容易让读者变得对 C++ 胸有成竹,包括我。但我后来又意外发现,一旦语法细节叠加起来,就是编程难度上的指数爆炸,A Tour of C++ 就刻意不提这现象,虽然本来就无能为力且也没必要。Bjarne Stroustrup 说过他给自己对 C++ 的理解打分的话,七十分。 比如 int *a 和 int a[10] 一看就知道分别声明了 int 指针和 int 数组,但 int *a[10] 又声明了什么呢?A Tour of C++ 就没有讲,它只提及了 * , [] , & 是 declaration operators。但 "declaration operators" 这个看似正式,但并不是 C++ 标准的术语(大概),而且 Declaration 语法 本身就非常复杂,我都没想到声明时原来还有那么多东西可以塞进去,鬼知道怎么匹配它们之间的关系,显然理解难度等于 N 次方。C 业界甚至曾流传过错误的民间说法: The Spiral Rule 知乎上也有人说明了 当 move 语义,默认参数,模板等结合起来 C++ 就变得面目可憎 。 C++ 为了兼容 C,背上了很多历史包袱,与此又添加了改进这些历史包袱的现代语法。于是现代 C++ 就同时存在两种非正交的新旧语法,比如 NULL vs nullptr,const char * vs std::string,header file vs module,enum vs enum class,union vs std::variant,函数的返回类型声明在前 vs 函数参数后面用箭头声明的返回类型等。C++ 改进还特别慢,以三年为周期单位,搞笑的是 C++20 引入了 module,但还不能直接 import std,要到 C++23 才行。我估计 C++ 到死也没法 deprecate 那些该死的历史包袱了。我看了 LeetCode 上的 C++ solutions,绝大部分写的其实是 C,而不是 C++。 再次,C++ 同时支持多个编程范式:过程式编程,面向对象编程,泛型编程,元编程,函数式编程。再加上标准库编程(我胡诌的,也包括容器,算法等)和系统编程(包括 I/O,文件,网络等操作系统 API)。其中标准库编程产生了 Erase–remove idiom 这个诡异的奇技淫巧。多种编程范式叠加起来,再次爆炸。 最后,我发现 C++ 有太多 implication 了: int a = 1.2 ,后者会被 implicitly converted;base class 的某函数被声明为 virtual 时,所有 derived functions 也会被 implicitly 声明为 virtual,我在 r/cpp_questions 问了好多问题才 get 这语法; int a 看似一个 declaration,但也可能是 defination,即 initialiazed as zero implicitly;所有 class 的 special function members 应该会 be defined implicitly,除非定义其中一个 member function explicitly 或是 delete 它,于是看到若某人说某 class 没有 constructor,意思其实是没有 define constructor explicitly,或是没有 user-defined constructor(其实和前一子句同一个意思),或是故意声明为 =delete。此外这害得你很容易搞不清楚 declaration,initialization,definiation,implementation,user-defined 之间的关系,因为有些词语是 ambiguous, =delete 是一种 definition 吗, T a = T() 是 assignment,但也是 initialization 吗?上文提到的语法叠加灾难我还可以容忍,但这种 C++ implicit 语法让我出离愤怒!怪不得 Linus 要破口大骂。Crap! 所以,C++ 难。 Written with StackEdit .
c++ 计算机科学
C++ Templates(第2版 英文版) 豆瓣
C++ Templates
作者: [美] David Vandevoorde / [德] Nicolai M.Josuttis 人民邮电出版社 2018 - 5
本书是同名经典畅销图书的全新升级版本,针对C++11、C++14、C++17标准进行了全面更新,并对所有的新语言特性(包括可变参数模板、通用lambda、类模板参数推导等)进行了解释。
全书共28章。首先全面介绍了本书的内容结构和相关情况。第1部分(第1~11章)介绍了模板的基本概念,第2部分(第12~17章)深入阐述了模板的细节,第3部分(第18~28章)介绍了C++模板所支持的基本设计技术。附录A、附录B、附录C、附录D和附录E分别为一处定义原则、值类别、重载解析、标准类型实用程序和概念的相关资料。
本书适合对C++模板技术感兴趣的有一定经验的程序员阅读。
现代C++探秘 豆瓣
Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers
作者: Peter Gottschling 电子工业出版社 2017 - 4
如今科学工程项目越来越大、越来越复杂,许多项目都采用 C++编程语言来完成。《现代C++探秘:编码、工程与科研必修(基于C++ 14)(英文版)》深入介绍了基于 C++编程语言高级功能的复杂方法,旨在帮助您快速入门,实现如表达式模板之类的高级技术。您还将学习如何使用 C++编程语言的强大类库:标准模板库( STL)以及用于算法、线性代数、微分方程、图形的科学类库。《现代C++探秘:编码、工程与科研必修(基于C++ 14)(英文版)》演示了如何使用面向对象、泛型编程、元编程和过程技术来编写清晰明了、富有表达力的软件。当您学完《现代C++探秘:编码、工程与科研必修(基于C++ 14)(英文版)》,将掌握如何使用 C++编程语言来编写高质量、高性能的软件。