Skip to content

Commit

Permalink
add changkun#12: prepare English supports
Browse files Browse the repository at this point in the history
  • Loading branch information
changkun committed Apr 13, 2018
1 parent 84a02f7 commit c9e3040
Show file tree
Hide file tree
Showing 25 changed files with 187 additions and 7 deletions.
54 changes: 54 additions & 0 deletions README-en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<img src="assets/cover-2nd-en.png" alt="logo" height="600" align="right" />

# C++11/14/17 On the Fly

![](https://img.shields.io/badge/version-v2-green.svg) ![](https://img.shields.io/badge/language-English-blue.svg) [![](https://img.shields.io/badge/$-donate-ff69b4.svg)](./assets/donate.md) [![](https://img.shields.io/badge/chat-community-667ed5.svg)](./assets/community.md)

> This book is adapting to C++17
## Languages

- 🇨🇳 [简体中文](./README.md)
- 🇬🇧 English

## Purpose

The book claims "On the Fly". Its intent is to provide a comprehensive introduction to the relevant features regarding modern C++ (before 2020s).
Readers can choose interesting content according to the following table of content to learn and quickly familiarize the new features you would like to learn.
Readers should aware that all of these features are not required. It should be leart when you really need it.

At the same time, instead of grammar-only, the book introduces the historical background as simple as possible of its technical requirements, which provides great help in understanding why these features comes out.

In addition, The author would like to encourage that readers should be able to use C++17 directly in their new projects and migrate their old projects to C++17 gradually after read the book.

## Targets

- This book assumes that readers are already familiar with traditional C++ (e.g. C++98), at least they do not have any difficulty in reading traditional C++ code. In other words, those who have long experience in traditional C++ and people who desire to quickly understand the features of modern C++ in a short period of time are well suited to read the book;

- This book introduces to a certain extent of the dark magic of modern C++. However, these magics are very limited, they are not suitable for readers who want to learn advanced C++. The purpose of this book is offering a quick start for modern C++. Of course, advanced readers can also use this book to review and examine themselves on modern C++.

## Start

You can choose from the following reading methods:

- [GitHub Online](./book/en-us/toc.md)
- [PDF document]
- [Website]

## Code

Each chapter of this book has a lot of code. If you encounter problems when writing your own code with the introductory features of the book, you might as well read the source code attached to the book. You can find the book [here](./code). All the code organized by chapter, the folder name is the chapter number.

## Exercises

There are few exercises At the end of each chapter of the book. It is for testing whether you can use the knowledge points in the current chapter. You can find the possible answer to the problem from [here](./exercise). The folder name is the chapter number.

## Acknowledgements

This book is originally written in Chinese, and the author's time, skills and languages are limited. If readers find any mistakes of the book or any language improvements, please feel free to open an [issue](https://github.com/changkun/modern-cpp-tutorial/issues). The author would like to appreciate all of the contributors of this book for discovering mistakes:

[recolic](https://www.gitbook.com/@recolic), [sinomiko](https://www.gitbook.com/@sinomiko), [jackwish](https://www.gitbook.com/@jackwish), [asmwarrior](https://www.gitbook.com/@asmwarrior), [garicc](https://www.gitbook.com/@ihpy), [jiangwenhan](https://www.gitbook.com/@jiangwenhan), [liangx8](https://www.gitbook.com/@liangx8), [slivermeteor](https://github.com/slivermeteor), [inkedawn](https://github.com/inkedawn), [zhaoyao73](https://github.com/zhaoyao73), [sundy-li](https://github.com/sundy-li), [dontpanic92](https://github.com/dontpanic92)

## 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).
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

# 《高速上手 C++11/14/17》

![](https://img.shields.io/badge/version-v2-green.svg) [![](https://img.shields.io/badge/%C2%A5-%E8%B5%9E%E5%8A%A9-ff69b4.svg)](./assets/donate.md) [![](https://img.shields.io/badge/chat-%E4%BA%A4%E6%B5%81-667ed5.svg)](./assets/community.md)
![](https://img.shields.io/badge/version-v2-green.svg)
![](https://img.shields.io/badge/language-%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87-red.svg)
[![](https://img.shields.io/badge/%C2%A5-%E8%B5%9E%E5%8A%A9-ff69b4.svg)](./assets/donate.md) [![](https://img.shields.io/badge/chat-%E4%BA%A4%E6%B5%81-667ed5.svg)](./assets/community.md)

> 本书正在适配 C++17 新特性,尽请期待。
## 语言

- 🇨🇳 [简体中文](./README.md)
- 🇬🇧 [English](./README-en-us.md)

## 本书目的

本书号称『高速上手』,从内容上对二十一世纪二十年代之前产生 C++ 的相关特性做了非常相对全面的介绍,读者可以自行根据下面的目录选取感兴趣的内容进行学习,快速熟悉需要了解的内容。这些特性并不需要全部掌握,只需针对自己的使用需求和特定的应用场景,学习、查阅最适合自己的新特性即可。
Expand All @@ -23,8 +30,8 @@

你可以选择以下几种阅读方式:

1. [GitHub 在线](./book/toc.md)
2. [PDF 文档](./pdf/modern-cpp-tutorial.pdf)
1. [GitHub 在线](./book/zh-cn/toc.md)
2. [PDF 文档](./pdf/zh-cn/modern-cpp-tutorial.pdf)
3. [网站]

## 相关代码
Expand Down
5 changes: 5 additions & 0 deletions assets/community-international.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Community

This book offers a reader community, you can join this Telegram:

TBA
Binary file added assets/cover-2nd-en.afphoto
Binary file not shown.
Binary file added assets/cover-2nd-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/donate-international.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Donate

To donate the author:

TBA
109 changes: 109 additions & 0 deletions book/en-us/toc.md
Original file line number Diff line number Diff line change
@@ -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).
File renamed without changes.
2 changes: 1 addition & 1 deletion book/01-intro.md → book/zh-cn/01-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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++代码进行分离编译,再统一链接这种做法,例如:

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions book/05-pointers.md → book/zh-cn/05-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 并没有任何智能指针引用它,因此这块内存资源也会被释放。
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pdf/Makefile → pdf/zh-cn/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pdf: markdown

markdown:
@echo "Copy markdown files..."
@cp -r ../book/* .
@cp -r ../../book/zh-cn/* .
@echo "Aggregating markdown files..."
@python3 aggregator.py

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c9e3040

Please sign in to comment.