Skip to content

Instantly share code, notes, and snippets.

@dszakallas
Created July 12, 2017 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dszakallas/3636a42b43d09ac2721046369a0996f1 to your computer and use it in GitHub Desktop.
Save dszakallas/3636a42b43d09ac2721046369a0996f1 to your computer and use it in GitHub Desktop.
universal reference
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