Created
July 12, 2017 20:19
-
-
Save dszakallas/3636a42b43d09ac2721046369a0996f1 to your computer and use it in GitHub Desktop.
universal reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> void f(T&& param); // param is now a universal reference | |
int x = 27; | |
const int cx = x; | |
const int& rx = x; | |
f(x); // x is lvalue, so T is int&, | |
// param's type is also int& | |
f(cx); // cx is lvalue, so T is const int&, | |
// param's type is also const int& | |
f(rx); // rx is lvalue, so T is const int&, | |
// param's type is also const int& | |
f(27); // 27 is rvalue, so T is int, | |
// param's type is therefore int&& |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment