As we discussed in the previous article, && means universal references when type deduction is involved.
But internally, the template parameter is getting instantiated twice, once of Lvalue and the other Rvalue. The below program demonstrates it.
In this code, when func is called with x, the int Lvalue version of it gets instantiated. i.e
When func is called the second time with 2, the int Rvalue version of it gets instantiated (see code below). Hence the value count is 0 in both the cases.
But internally, the template parameter is getting instantiated twice, once of Lvalue and the other Rvalue. The below program demonstrates it.
In this code, when func is called with x, the int Lvalue version of it gets instantiated. i.e
When func is called the second time with 2, the int Rvalue version of it gets instantiated (see code below). Hence the value count is 0 in both the cases.
Understanding universal references
Reviewed by zeroingTheDot
on
February 18, 2018
Rating:
No comments: