Skip to content

Instantly share code, notes, and snippets.

@ratmcu
Created April 22, 2022 04:00
Show Gist options
  • Save ratmcu/f7097475f0c61b4e4df38de57951040a to your computer and use it in GitHub Desktop.
Save ratmcu/f7097475f0c61b4e4df38de57951040a to your computer and use it in GitHub Desktop.
example that shows off a function that can accept a lvalue reference as well as a rvalue
#include <iostream>
template<typename T>
void fnc(T&& x)
{
// std::cout << x;
x++;
}
int main()
{
fnc(10); // Nope!
// This works instead:
int x = 10;
fnc(x);
std::cout << x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment