From 35c524d171e1e05e14f72b8e36ce3127395da876 Mon Sep 17 00:00:00 2001 From: BAKEZQ Date: Mon, 18 Mar 2019 20:54:30 +0800 Subject: [PATCH] Change answer Ex16.42 Solution to Excercise 16.42 is uncomplete. Added explanation. --- ch16/README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ch16/README.md b/ch16/README.md index 4e0a2c39..5cfe63c8 100644 --- a/ch16/README.md +++ b/ch16/README.md @@ -340,7 +340,7 @@ Yes. Specify the parameter explicitly: > int a = 6; double b = 6.1231; > std::cout << std::max(a, b) << std::endl; > ``` -> Normal conversions also apply for arguments whose template type parameter is explicitly specified +> Normal conversions also apply for arguments whose template type parameter is explicitly specified. ## Exercise 16.38 @@ -395,9 +395,13 @@ More safer solution: <[Better `sum`](ex16_41_sum.cpp)> > (c) g(i * ci); > ``` -- (a) `int&` -- (b) `const int&` -- (c) `int` +- (a) T: `int&` val: int& && -> int & +- (b) T: `const int&` val: const int& && -> const int & +- (c) T: `int` val: int && + +> When we pass an lvalue `int` to a function parameter that is an rvalue reference to a template type parameter `T&&`, the compiler deduces the template type parameter as the argument’s lvalue reference type `int &`. + +> `X& &`, `X& &&`, and `X&& &` all collapse to type `X&`. ## Exercise 16.43