book: add missing header files (#74)

This commit is contained in:
Swastik Baranwal
2019-09-18 19:57:08 +05:30
committed by Ou Changkun
parent 934eb895c5
commit 0aa031f0f6
3 changed files with 14 additions and 1 deletions

View File

@@ -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)

View File

@@ -286,6 +286,7 @@ such as:
```cpp
#include <initializer_list>
#include <vector>
class MagicFoo {
public:
std::vector<int> vec;
@@ -342,6 +343,7 @@ and the structured bindings let us write code like this:
```cpp
#include <iostream>
#include <tuple>
std::tuple<int, double, std::string> 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 <iostream>
template<typename... Ts>
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 <iostream>
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 <iostream>
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 <string>
#include <map>
#include <iostream>
template <typename Key, typename Value, typename F>
void update(std::map<Key, Value>& m, F foo) {
// TODO:

View File

@@ -232,6 +232,7 @@ int main() {
```cpp
#include <initializer_list>
#include <vector>
class MagicFoo {
public:
std::vector<int> vec;
@@ -277,6 +278,7 @@ C++17 完善了这一设定,给出的结构化绑定可以让我们写出这
```cpp
#include <iostream>
#include <tuple>
std::tuple<int, double, std::string> f() {
return std::make_tuple(1, 2.3, "456");
@@ -823,6 +825,7 @@ int main() {
C++11 引入了委托构造的概念,这使得构造函数可以在同一个类中一个构造函数调用另一个构造函数,从而达到简化代码的目的:
```cpp
#include <iostream>
class Base {
public:
int value1;
@@ -847,6 +850,7 @@ int main() {
在传统 C++ 中构造函数如果需要继承是需要将参数一一传递的这将导致效率低下。C++11 利用关键字 using 引入了继承构造函数的概念:
```cpp
#include <iostream>
class Base {
public:
int value1;