Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zhqu1148980644 authored Mar 20, 2019
1 parent 57f55ee commit e375c61
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions ch16/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,27 +455,36 @@ f(42); f(p); f(ci); f(p2);
```
> Answer:
```cpp
g(42); //type: int(rvalue) call template 3 T: int instantiation: void g(int)
g(p); //type: int * call template 4 T: int instantiation: void g(int *)
g(ci); //type: const int call template 3 T: const int instantiation: void g(const int)
g(p2); //type: const int * call template 4 T: const int instantiation: void g(const int *)
f(42); //type: int(rvalue) call template 1 T: int instantiation: void f(int)
f(p); //type: int * call template 1 T: int * instantiation: void f(int *)
# f(int *) is an exact match for p(int *) while f(const int *) has an conversion from int * to const int *.
f(ci); //type: const int call template 1 T: const int instantiation: void f(const int)
f(p2); //type: const int * call template 2 T:int instantiation: void f(const int *)
g(42); // type: int(rvalue) call template 3 T: int instantiation: void g(int)
g(p); // type: int * call template 4 T: int instantiation: void g(int *)
g(ci); // type: const int call template 3 T: const int instantiation: void g(const int)
g(p2); // type: const int * call template 4 T: const int instantiation: void g(const int *)
f(42); // type: int(rvalue) call template 1 T: int instantiation: void f(int)
f(p); // type: int * call template 1 T: int * instantiation: void f(int *)
// f(int *) is an exact match for p(int *) while f(const int *) has an conversion from int * to const int *.
f(ci); // type: const int call template 1 T: const int instantiation: void f(const int)
f(p2); // type: const int * call template 2 T:int instantiation: void f(const int *)
```
## Exercise 16.51
## Exercise 16.50
> Define the functions from the previous exercise so that they print an identifying message. Run the code from that exercise. If the calls behave differently from what you expected, make sure you understand why.
[overload template](ex16_50_overload_template.cpp)
## Exercise 16.51
> Determine what sizeof...(Args) and sizeof...(rest) return for each call to foo in this section.
```cpp
template <typename T, typename ... Args>
void foo(const T & t, const Args & ... rest);
int i = 0; double d = 3.14; string s = "how";
foo(i, s, 42, d); # input in Args: string, int(rvalue), double sizeof...(Args): 3 sizeof...(rest): 3
foo(s, 42, "hi"); # input in Args: int(rvalue), const char[3] sizeof...(Args): 2 sizeof...(rest): 2
foo(d, s); # input in Args: string sizeof...(Args): 1 sizeof...(rest): 1
foo("hi"); # input in Args: None sizeof...(Args): 0 sizeof...(rest): 0
foo(i, s, s, d); # input in Args: string, string, double sizeof...(Args): 3 sizeof...(rest): 3
foo(i, s, 42, d); // input in Args: string, int(rvalue), double sizeof...(Args): 3 sizeof...(rest): 3
foo(s, 42, "hi"); // input in Args: int(rvalue), const char[3] sizeof...(Args): 2 sizeof...(rest): 2
foo(d, s); // input in Args: string sizeof...(Args): 1 sizeof...(rest): 1
foo("hi"); // input in Args: None sizeof...(Args): 0 sizeof...(rest): 0
foo(i, s, s, d); // input in Args: string, string, double sizeof...(Args): 3 sizeof...(rest): 3
```
# Exercise 16.52
> Write a program to check your answer to the previous question.
[variadic template](ex16_52_variadic_template.cpp)

0 comments on commit e375c61

Please sign in to comment.