You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/en-us/02-usability.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -286,6 +286,7 @@ such as:
286
286
287
287
```cpp
288
288
#include<initializer_list>
289
+
#include<vector>
289
290
classMagicFoo {
290
291
public:
291
292
std::vector<int> vec;
@@ -342,6 +343,7 @@ and the structured bindings let us write code like this:
342
343
343
344
```cpp
344
345
#include <iostream>
346
+
#include <tuple>
345
347
346
348
std::tuple<int, double, std::string> f() {
347
349
return std::make_tuple(1, 2.3, "456");
@@ -776,6 +778,7 @@ how to unpack the parameters?
776
778
First, we can use `sizeof...` to calculate the number of arguments:
777
779
778
780
```cpp
781
+
#include <iostream>
779
782
template<typename... Ts>
780
783
void magic(Ts... args) {
781
784
std::cout << sizeof...(args) << std::endl;
@@ -919,6 +922,7 @@ C++11 introduces the concept of a delegate construct, which allows a constructor
919
922
in a constructor in the same class, thus simplifying the code:
920
923
921
924
```cpp
925
+
#include<iostream>
922
926
classBase {
923
927
public:
924
928
int value1;
@@ -943,6 +947,7 @@ int main() {
943
947
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:
944
948
945
949
```cpp
950
+
#include <iostream>
946
951
class Base {
947
952
public:
948
953
int value1;
@@ -1091,6 +1096,10 @@ This section introduces the enhancements to language usability in modern C++, wh
1091
1096
1. Using structured binding, implement the following functions with just one line of function code:
0 commit comments