From 0aa031f0f6c120ff99f5a503c081672691ad5c54 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Wed, 18 Sep 2019 19:57:08 +0530 Subject: [PATCH] book: add missing header files (#74) --- book/en-us/01-intro.md | 2 +- book/en-us/02-usability.md | 9 +++++++++ book/zh-cn/02-usability.md | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/book/en-us/01-intro.md b/book/en-us/01-intro.md index ac97c02..96619c5 100644 --- a/book/en-us/01-intro.md +++ b/book/en-us/01-intro.md @@ -138,7 +138,7 @@ Don't worry at the moment, we will come to meet them in our later chapters. ## Further Readings - [A Tour of C++ (2nd Edition) Bjarne Stroustrup](https://www.amazon.com/dp/0134997832/ref=cm_sw_em_r_mt_dp_U_GogjDbHE2H53B) -- [C++ History](http://en.cppreference.com/w/cpp/language/history) + [History of C++](http://en.cppreference.com/w/cpp/language/history) - [C++ compiler support](https://en.cppreference.com/w/cpp/compiler_support) - [Incompatibilities Between ISO C and ISO C++](http://david.tribble.com/text/cdiffs.htm#C99-vs-CPP98) diff --git a/book/en-us/02-usability.md b/book/en-us/02-usability.md index 9ff5b84..2c5dc99 100644 --- a/book/en-us/02-usability.md +++ b/book/en-us/02-usability.md @@ -286,6 +286,7 @@ such as: ```cpp #include +#include class MagicFoo { public: std::vector vec; @@ -342,6 +343,7 @@ and the structured bindings let us write code like this: ```cpp #include +#include std::tuple f() { return std::make_tuple(1, 2.3, "456"); @@ -776,6 +778,7 @@ how to unpack the parameters? First, we can use `sizeof...` to calculate the number of arguments: ```cpp +#include template void magic(Ts... args) { std::cout << sizeof...(args) << std::endl; @@ -919,6 +922,7 @@ C++11 introduces the concept of a delegate construct, which allows a constructor in a constructor in the same class, thus simplifying the code: ```cpp +#include class Base { public: int value1; @@ -943,6 +947,7 @@ int main() { In traditional C++, constructors need to pass arguments one by one if they need inheritance, which leads to inefficiency. C++11 introduces the concept of inheritance constructors using the keyword using: ```cpp +#include class Base { public: int value1; @@ -1091,6 +1096,10 @@ This section introduces the enhancements to language usability in modern C++, wh 1. Using structured binding, implement the following functions with just one line of function code: ```cpp + #include + #include + #include + template void update(std::map& m, F foo) { // TODO: diff --git a/book/zh-cn/02-usability.md b/book/zh-cn/02-usability.md index 14a625c..d91f99e 100644 --- a/book/zh-cn/02-usability.md +++ b/book/zh-cn/02-usability.md @@ -232,6 +232,7 @@ int main() { ```cpp #include +#include class MagicFoo { public: std::vector vec; @@ -277,6 +278,7 @@ C++17 完善了这一设定,给出的结构化绑定可以让我们写出这 ```cpp #include +#include std::tuple f() { return std::make_tuple(1, 2.3, "456"); @@ -823,6 +825,7 @@ int main() { C++11 引入了委托构造的概念,这使得构造函数可以在同一个类中一个构造函数调用另一个构造函数,从而达到简化代码的目的: ```cpp +#include class Base { public: int value1; @@ -847,6 +850,7 @@ int main() { 在传统 C++ 中,构造函数如果需要继承是需要将参数一一传递的,这将导致效率低下。C++11 利用关键字 using 引入了继承构造函数的概念: ```cpp +#include class Base { public: int value1;