add #12: prepare English supports

This commit is contained in:
Changkun Ou
2018-04-13 09:43:01 +02:00
parent 84a02f7183
commit c9e3040285
25 changed files with 187 additions and 7 deletions

109
book/en-us/toc.md Normal file
View File

@@ -0,0 +1,109 @@
# C++ 11/14/17 On The Fly
> This book adapting to C++17 and translating to English
## Table of Contents
- [**Preface**](./00-preface.md)
- [**Chapter 01 Towards C++11/14/17**](./01-intro.md)
+ 1.1 Deprecated Features
+ 1.2 Compatibility with C
+ Further Readings
- [**Chapter 02 Language Usability Enhancements**](./02-usability.md)
+ 2.1 Constants
- nullptr
- constexpr
+ 2.2 Variables & Initialization
- Conditional Statement
- Initializer List
- Structured binding
+ 2.3 Type Deduction
- auto
- decltype
- Tail return type
- decltype(auto)
+ 2.4 Control Flow
- if constexpr
- Range-based for loop
+ 2.5 Templates
- External templates
- The ">"
- Type alias templates
- Default template parameters
- Variadic templates
- Fold expression
+ 2.6 Object-oriented
- Delegate constructor
- Inheritance constructor
- Explicit virtual function overwrite
- override
- final
- Explicit delete default function
- Strongly typed enumerations
- [**Chapter 03 Language Runtime Enhancements**](./03-runtime.md)
+ Lambda expression
+ Basics
+ Value capture
+ Reference capture
+ Implicit capture
+ Expression capture
+ Generic lambda
+ Function object wrapper
+ std::function
+ std::bind/std::placeholder
+ rvalue reference
+ lvalue, rvalue, prvalue, xvalue
+ rvalue reference & lvalue reference
+ Move semantics
+ Perfect forwarding
- [**Chapter 04 Sandard Library: Containers**](./04-containers.md)
+ `std::array`
+ `std::forward_list`
+ `std::unordered_set`
+ `std::unordered_map`
+ `std::tuple`
+ basic operation
+ runtime indexing
+ merge and iteration
- [**Chapter 05 Sandard Library: Pointers**](./05-pointers.md)
+ RAII and reference counting
+ `std::shared_ptr`
+ `std::unique_ptr`
+ `std::weak_ptr`
- [**Chapter 06 Sandard Library: Regular Expression**](./06-regex.md)
+ Regular Expression Introduction
+ Normal characters
+ Special characters
+ Determinative
+ `std::regex`
+ `std::regex`
+ `std::regex_match`
+ `std::match_results`
- [**Chapter 07 Sandard Library: Threads and Concurrency**](./07-thread.md)
+ `std::thread`
+ `std::mutex`
+ `std::unique_lock`
+ `std::future`
+ `std::packaged_task`
+ `std::condition_variable`
- [**Chapter 08 Sandard Library: File System**](./08-filesystem.md)
- [**Chapter 09 Minor Features**](./09-others.md)
+ New Types
+ `long long int`
+ `noexcept`
+ Literal
+ Raw string literal
+ Custom string literal
+ Math Library
- [**Chapter 10 Outlook: Introduction of C++20**](./10-cpp20.md)
+ Concept
+ Range
+ Module
+ Coroutine
- [**Appendix: Further Study Materials**](./appendix.md)
Table of Content | Last Chapter | [Next Chapter: Preface](./00-preface.md)
## Licenses
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a><br />This work is written by [Ou Changkun](https://changkun.de) and licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License</a>. The code of this repository is open sourced under the [MIT license](./LICENSE).

View File

@@ -45,7 +45,7 @@ InstalledDir: /Library/Developer/CommandLineTools/usr/bin
出于一些不可抗力、历史原因,我们不得不在 C++ 中使用一些 C 语言代码(甚至古老的 C 语言代码),例如 Linux 系统调用。在 C++1x 出现之前大部分人当谈及『C 与 C++ 的区别是什么』时,普遍除了回答面向对象的类特性、泛型编程的模板特性外,就没有其他的看法了,甚至直接回答『差不多』,也是大有人在。图 1.2 中的韦恩图大致上回答了 C 和 C++ 相关的兼容情况。
![图 1.2: C 和 C++ 互相兼容情况](../assets/comparison.png)
![图 1.2: C 和 C++ 互相兼容情况](../../assets/comparison.png)
从现在开始,你的脑子里应该树立『**C++ 不是 C 的一个超集**』这个观念(而且从一开始就不是,后面的[进一步阅读的参考文献](#进一步阅读的参考文献)中给出了 C++98 和 C99 之间的区别)。在编写 C++ 时,也应该尽可能的避免使用诸如 `void*` 之类的程序风格。而在不得不使用 C 时,应该注意使用 `extern "C"` 这种特性,将 C 语言的代码与 C++代码进行分离编译,再统一链接这种做法,例如:

View File

@@ -162,11 +162,11 @@ int main() {
运行结果是 A, B 都不会被销毁,这是因为 a,b 内部的 pointer 同时又引用了 `a,b`,这使得 `a,b` 的引用计数均变为了 2而离开作用域时`a,b` 智能指针被析构,却智能造成这块区域的引用计数减一,这样就导致了 `a,b` 对象指向的内存区域引用计数不为零,而外部已经没有办法找到这块区域了,也就造成了内存泄露,如图所示:
![](../assets/pointers1.png)
![](../../assets/pointers1.png)
解决这个问题的办法就是使用弱引用指针 `std::weak_ptr``std::weak_ptr`是一种弱引用(相比较而言 `std::shared_ptr` 就是一种强引用)。弱引用不会引起引用计数增加,当换用弱引用时候,最终的释放流程如下图所示:
![](../assets/pointers2.png)
![](../../assets/pointers2.png)
在上图中,最后一步只剩下 B而 B 并没有任何智能指针引用它,因此这块内存资源也会被释放。