update: prepare C++20

This commit is contained in:
Changkun Ou
2019-07-08 13:17:58 +02:00
parent 7204a23882
commit 407148cfff
28 changed files with 66 additions and 67 deletions

View File

@@ -4,7 +4,7 @@
## 提交 Issue
『C++ 11/14/17』的 issue 用于追踪书中存在的原则性的描述错误、存在的 `typo` 错误,以及向本书作者提问等。
『C++ 11/14/17/20』的 issue 用于追踪书中存在的原则性的描述错误、存在的 `typo` 错误,以及向本书作者提问等。
- 通常情况下,你可能会发现书中某个段落存在错别字、语义错误、文法错误等。
这都是 `typo` 错误。如果该错误已经对你的阅读造成了一定障碍,
@@ -24,7 +24,7 @@
## 提交 Pull request
『C++ 11/14/17』是一本开源书籍任何人都可以参与贡献自己 PR。但在提交 PR 之前请仔细阅读下面的说明:
『C++ 11/14/17/20』是一本开源书籍,任何人都可以参与贡献自己 PR。但在提交 PR 之前请仔细阅读下面的说明:
- 当你认为需要提交一个 PR 时,请确保 [issue 列表](https://github.com/changkun/modern-cpp-tutorial/issues)中,已经包含了你想要解决的问题。
如果没有,请参考**提交 Issue** 一节中的描述,提交你的 issue再提交你的 PR。

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2016 - Present Changkun Ou <hi@changkun.us>
Copyright (c) 2016 - 2019 Changkun Ou <hi@changkun.us>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,12 +1,9 @@
<img src="assets/cover-2nd-en.png" alt="logo" height="600" align="right" />
# C++11/14/17 On the Fly
# C++11/14/17/20 On the Fly
![](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)](./README.md) [![](https://img.shields.io/badge/language-English-blue.svg)](./README-en-us.md) [![](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 and translating to 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).
@@ -15,7 +12,7 @@ Readers should aware that all of these features are not required. It should be l
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.
In addition, The author would like to encourage that readers should be able to use modern C++ directly in their new projects and migrate their old projects to modern C++ gradually after read the book.
## Targets
@@ -51,4 +48,4 @@ The author has limited time and language skills. If readers find any mistakes of
## 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).
<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 was 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

@@ -1,6 +1,6 @@
<img src="assets/cover-2nd.png" alt="logo" height="600" align="right" />
<img src="assets/cover-2nd.png" alt="logo" height="550" align="right" />
# 《高速上手 C++11/14/17》
# 《高速上手 C++11/14/17/20
[![](https://img.shields.io/badge/language-%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87-red.svg)](./README.md) [![](https://img.shields.io/badge/language-English-blue.svg)](./README-en-us.md)
[![](https://img.shields.io/badge/%C2%A5-%E8%B5%9E%E5%8A%A9-ff69b4.svg)](./assets/donate.md)
@@ -11,7 +11,7 @@
同时,本书在介绍这些特性的过程中,尽可能简单明了的介绍了这些特性产生的历史背景和技术需求,这为理解这些特性、运用这些特性提供了很大的帮助。
此外,笔者希望读者在阅读本书后,能够努力在新项目中直接使用 C++17,并努力将旧项目逐步迁移到 C++17。也算是笔者为推进现代 C++ 的普及贡献了一些绵薄之力。
此外,笔者希望读者在阅读本书后,能够努力在新项目中直接使用现代 C++,并努力将旧项目逐步迁移到现代 C++。也算是笔者为推进现代 C++ 的普及贡献了一些绵薄之力。
## 目标读者

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

BIN
assets/cover-2nd.afphoto Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

0
book/en-us/00-preface.md Normal file
View File

View File

@@ -1,9 +1,9 @@
# C++ 11/14/17 On The Fly
# C++ 11/14/17/20 On The Fly
## Table of Contents
- [**Preface**](./00-preface.md)
- [**Chapter 01 Towards C++11/14/17**](./01-intro.md)
- [**Chapter 01 Towards Modern C++**](./01-intro.md)
+ 1.1 Deprecated Features
+ 1.2 Compatibility with C
+ Further Readings
@@ -39,69 +39,71 @@
- Explicit delete default function
- Strongly typed enumerations
- [**Chapter 03 Language Runtime Enhancements**](./03-runtime.md)
+ Lambda expression
+ 3.1 Lambda expression
+ Basics
+ Value capture
+ Reference capture
+ Implicit capture
+ Expression capture
+ Generic lambda
+ Function object wrapper
+ 3.2 Function object wrapper
+ std::function
+ std::bind/std::placeholder
+ rvalue reference
+ 3.3 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`
+ 4.1 `std::array` and `std::forward_list`
+ 4.2 Unordered containers
+ `std::unordered_set`
+ `std::unordered_map`
+ 4.3 Tuples `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`
+ 5.1 RAII and reference counting
+ 5.2 `std::shared_ptr`
+ 5.3 `std::unique_ptr`
- [**Chapter 06 Sandard Library: Regular Expression**](./06-regex.md)
+ Regular Expression Introduction
+ 6.1 Regular Expression Introduction
+ Normal characters
+ Special characters
+ Determinative
+ `std::regex`
+ 6.2 `std::regex` and related
+ `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`
+ 7.1 `std::thread`
+ 7.2 `std::mutex` and `std::unique_lock`
+ 7.3 `std::future` and `std::packaged_task`
+ 7.4 `std::condition_variable`
+ 7.5 `std::atomic` and memory order
+ 7.6 Transactional memory
- [**Chapter 08 Sandard Library: File System**](./08-filesystem.md)
+ 8.1 Documents and links
+ 8.2 `std::filesystem`
- [**Chapter 09 Minor Features**](./09-others.md)
+ New Types
+ 9.1 New Types
+ `long long int`
+ `noexcept`
+ Literal
+ 9.2 `noexcept` and its operates
+ 9.3 Literal
+ Raw string literal
+ Custom string literal
+ Math Library
+ 9.4 Math Library
- [**Chapter 10 Outlook: Introduction of C++20**](./10-cpp20.md)
+ Concept
+ Range
+ Module
+ Coroutine
- [**Appendix: Further Study Materials**](./appendix.md)
- [**Appendix 1: Further Study Materials**](./appendix1.md)
- [**Appendix 2: Modern C++ Best Practices**](./appendix2.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).
<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 was 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

@@ -9,9 +9,9 @@ order: 0
## 引言
C++ 是一个用户群体相当大的语言。从 C++98 的出现到 C++11 的正式定稿经历了长达十年多之久的积累。C++14/17 则是作为对 C++11 的重要补充和优化,所有这些新标准中扩充的特性,给 C++ 这门语言注入了新的活力。
那些还在坚持使用**传统 C++**(本书把 C++98 及其之前的 C++ 特性均称之为传统 C++)而未接触过 C++11/14/17 的 C++ 程序员在见到诸如 Lambda 表达式这类全新特性时,甚至会流露出『学的不是同一门语言』的惊叹之情。
那些还在坚持使用**传统 C++**(本书把 C++98 及其之前的 C++ 特性均称之为传统 C++)而未接触过 C++11/14/17/20 的 C++ 程序员在见到诸如 Lambda 表达式这类全新特性时,甚至会流露出『学的不是同一门语言』的惊叹之情。
**C++1x** (或**现代 C++**,本书中均指 C++11/14/17) 为传统 C++ 注入的大量特性使得整个 C++ 变得更加像一门现代化的语言。C++1x 不仅仅增强了 C++ 语言自身的可用性,`auto` 关键字语义的修改使得我们更加有信心来操控极度复杂的模板类型。同时还对语言运行期进行了大量的强化Lambda 表达式的出现让 C++ 具有了『匿名函数』的『闭包』特性,而这一特性几乎在现代的编程语言(诸如 Python/Swift/... )中已经司空见惯,右值引用的出现解决了 C++ 长期以来被人诟病的临时对象效率问题等等。
**C++1x** (或**现代 C++**,本书中均指 C++11/14/17/20) 为传统 C++ 注入的大量特性使得整个 C++ 变得更加像一门现代化的语言。C++1x 不仅仅增强了 C++ 语言自身的可用性,`auto` 关键字语义的修改使得我们更加有信心来操控极度复杂的模板类型。同时还对语言运行期进行了大量的强化Lambda 表达式的出现让 C++ 具有了『匿名函数』的『闭包』特性,而这一特性几乎在现代的编程语言(诸如 Python/Swift/... )中已经司空见惯,右值引用的出现解决了 C++ 长期以来被人诟病的临时对象效率问题等等。
C++17 则是近三年依赖 C++ 社区一致推进的方向,也指出了**现代C++**编程的一个重要发展方向。尽管它的出现并不如 C++11 的分量之重,但它包含了大量小而美的语言与特性(例如结构化绑定),这些特性的出现再一次修正了我们在 C++ 中的编程范式。
@@ -36,7 +36,7 @@ C++17 则是近三年依赖 C++ 社区一致推进的方向,也指出了**现
本书每章中都出现了大量的代码,如果你在跟随本书介绍特性的思路编写自己的代码遇到问题时,不妨读一读随书附上的源码,你可以在[这里](../code)中找到书中介绍过的全部的源码,所有代码按章节组织,文件夹名称为章节序号。
[返回目录](./toc.md) | 上一章 | [下一章 迈向 C++11/14/17](./01-intro.md)
[返回目录](./toc.md) | 上一章 | [下一章 迈向现代 C++](./01-intro.md)
## 许可

View File

@@ -1,10 +1,10 @@
---
title: 第 1 章 迈向 C++11/14/17
title: 第 1 章 迈向现代 C++
type: book-zh-cn
order: 1
---
# 第 1 章 迈向 C++11/14/17
# 第 1 章 迈向现代 C++
[TOC]

View File

@@ -931,7 +931,7 @@ std::cout << new_enum::value3 << std::endl
## 总结
本节介绍了 C++11/14/17 中对语言可用性的增强,其中笔者认为最为重要的几个特性是几乎所有人都需要了解并熟练使用的:
本节介绍了 C++11/14/17/20 中对语言可用性的增强,其中笔者认为最为重要的几个特性是几乎所有人都需要了解并熟练使用的:
1. auto 类型推导
2. 范围 for 迭代

View File

@@ -130,7 +130,7 @@ Concepts TS 的发布到最后一次 C++17 的讨论会只相隔了不到四个
1. [Final features of C++17](https://meetingcpp.com/index.php/br/items/final-features-of-c17.html)
2. [C++17: will it be great or just ok?](https://codeplay.com/public/uploaded/filehost/0cbdaf_c++17post-oulu2016.pdf)
3. [Why Concepts didn't make C++17](http://honermann.net/blog/2016/03/06/why-concepts-didnt-make-cxx17/)
4. [C++11/14/17 编译器支持情况](http://en.cppreference.com/w/cpp/compiler_support)
4. [C++11/14/17/20 编译器支持情况](http://en.cppreference.com/w/cpp/compiler_support)
## 许可

View File

@@ -8,7 +8,7 @@ order: 11
首先,恭喜你阅读完本书 🎉 !笔者希望本书有提起你对现代 C++ 的兴趣。
正如本书引言部分提到的,本书只是一本带你快速领略现代 C++ 11/14/17 新特性的读物,而非进阶学习实践 C++『黑魔法』的内容。笔者当然也想到了这个需求,只是这样的内容非常艰深,鲜有受众。在此,笔者列出一些能够帮助你在此书基础之上进一步学习现代 C++ 的资料,希望能够祝你一臂之力:
正如本书引言部分提到的,本书只是一本带你快速领略现代 C++ 11/14/17/20 新特性的读物,而非进阶学习实践 C++『黑魔法』的内容。笔者当然也想到了这个需求,只是这样的内容非常艰深,鲜有受众。在此,笔者列出一些能够帮助你在此书基础之上进一步学习现代 C++ 的资料,希望能够祝你一臂之力:
- [C++ 参考](http://en.cppreference.com/w)
- [CppCon YouTube 频道](https://www.youtube.com/user/CppCon/videos)

View File

@@ -1,11 +1,9 @@
# 高速上手 C++ 11/14/17
> 正在向全面介绍 C++17 特性的内容过度
# 高速上手 C++ 11/14/17/20
## 目录
- [**序言**](./00-preface.md)
- [**第 1 章 迈向 C++11/14/17**](./01-intro.md)
- [**第 1 章 迈向现代 C++**](./01-intro.md)
+ 1.1 被弃用的特性
+ 1.2 与 C 的兼容性
+ 进一步阅读的参考文献
@@ -83,6 +81,8 @@
+ 7.2 `std::mutex``std::unique_lock`
+ 7.3 `std::future``std::packaged_task`
+ 7.4 `std::condition_variable`
+ 7.5 `std::atomic` 与内存顺序
+ 7.6 事务内存
- [**第 8 章 标准库: 文件系统**](./08-filesystem.md)
+ 8.1 文档与链接
+ 8.2 `std::filesystem`

View File

@@ -1,4 +1,4 @@
title = 'C++11/14/17 On the Fly'
title = 'C++11/14/17/20 On the Fly'
filename = 'modern-cpp-tutorial'
outputname='modern-cpp-tutorial'
revision = $(shell git describe --always --tags)

View File

@@ -10,7 +10,7 @@ ignores = ['TOC', 'Return to TOC', 'License', 'license']
with open('modern-cpp-tutorial.md', 'w') as outfile:
outfile.write("""---
title: "C++11/14/17 On the Fly"
title: "C++11/14/17/20 On the Fly"
author: Changkun Ou <hi@changkun.us>
copyright: cc-by-nc-nd 4.0
---

View File

@@ -161,7 +161,7 @@ $endif$
\thispagestyle{plain}
\begin{center}
{\LARGE\textbf{C++11/14/17 On the Fly}}
{\LARGE\textbf{C++11/14/17/20 On the Fly}}
\vspace{1em}
{\large Changkun Ou (hi@changkun.us)}
@@ -172,7 +172,7 @@ $endif$
\vspace{1em}
\textbf{\large License}
\noindent This work is written by \href{https://github.com/changkun}{Ou Changkun} and licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. \texttt{\small http://creativecommons.org/licenses/by-nc-nd/4.0/}
\noindent This work was written by \href{https://github.com/changkun}{Ou Changkun} and licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. \texttt{\small http://creativecommons.org/licenses/by-nc-nd/4.0/}
\vspace{8em}
\includegraphics{../../assets/cover-2nd-en}

View File

@@ -1,4 +1,4 @@
title = '高速上手 C++11/14/17'
title = '高速上手 C++11/14/17/20'
filename = 'modern-cpp-tutorial'
outputname='modern-cpp-tutorial'
revision = $(shell git describe --always --tags)

View File

@@ -9,7 +9,7 @@ ignores = ['TOC', '返回目录', '许可', 'license']
with open('modern-cpp-tutorial.md', 'w') as outfile:
outfile.write("""---
title: "高速上手 C++11/14/17"
title: "高速上手 C++11/14/17/20"
author: 欧长坤 <hi@changkun.us>
copyright: cc-by-nc-nd 4.0
---

View File

@@ -164,7 +164,7 @@ $endif$
\thispagestyle{plain}
\begin{center}
{\LARGE\textbf{高速上手 C++11/14/17}}
{\LARGE\textbf{高速上手 C++11/14/17/20}}
\vspace{1em}
{\large 欧长坤 (hi@changkun.us)}

View File

@@ -1,6 +1,6 @@
# changkun.de/modern-cpp
Welcome to Modern C++ Tutorial! This site is built with [hexo](http://hexo.io/). Site content is written in Markdown format located in `../book`. And all static files will be built into `./public`, which is served by a nginx server at [changkun.de](https://changkun.de).
Welcome to Modern C++ Tutorial! This site is built with [hexo](http://hexo.io/). Site content was written in Markdown format located in `../book`. And all static files will be built into `./public`, which is served by a nginx server at [changkun.de](https://changkun.de).
## Requirements

View File

@@ -1,6 +1,6 @@
# Site Configuration
title: 高速上手 C++ 11/14/17
subtitle: C++ 11/14/17 On the Fly
title: 高速上手 C++ 11/14/17/20
subtitle: C++ 11/14/17/20 On the Fly
description: "欧长坤"
author: 欧长坤
email: hi[at]changkun.us

View File

@@ -1,4 +1,4 @@
site_description: "现代 C++ | 高速上手 C++ 11/14/17"
site_description: "现代 C++ | 高速上手 C++ 11/14/17/20"
google_analytics:
root_domain: changkun.de/modern-cpp
moderncpp_version: 2.0.0

View File

@@ -13,7 +13,7 @@
</div><div class="right">
<h4>欧长坤 著</h4>
<h1>
高速上手<br>C++ 11/14/17
高速上手<br>C++ 11/14/17/20
</h1>
<h2>第二版</h2>
<p>

View File

@@ -3,7 +3,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title><%- page.title ? page.title : '' %> 高速上手 C++ 11/14/17 - C++ 11/14/17 On the Fly</title>
<title><%- page.title ? page.title : '' %> 高速上手 C++ 11/14/17/20 - C++ 11/14/17/20 On the Fly</title>
<meta charset="utf-8">
<meta name="description" content="<%- theme.site_description %>">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
@@ -23,7 +23,7 @@
</head>
<body class="<%- isIndex ? '' : 'docs' -%>">
<div id="mobile-bar" data-bg-text="高速上手 C++ 11/14/17" <%- isIndex ? 'class="top"' : '' %>>
<div id="mobile-bar" data-bg-text="高速上手 C++ 11/14/17/20" <%- isIndex ? 'class="top"' : '' %>>
<a class="menu-button"></a>
<a class="logo" href="/modern-cpp/"></a>
</div>

View File

@@ -1,7 +1,7 @@
<div id="header">
<a id="logo" href="<%- url_for("/modern-cpp/") %>">
<img src="<%- url_for("/modern-cpp/assets/cover-2nd.png") %>">
<span>高速上手 C++ 11/14/17</span><sup class="beta">beta</sup>
<span>高速上手 C++ 11/14/17/20</span><sup class="beta">beta</sup>
</a>
<ul id="nav">
<%- partial('partials/main_menu', { context: 'nav' }) %>