Can somebody give a simple example which demonstrates the functionality of std::ref
? I mean an example in which some other constructs (like tuples, or data type tem
void PrintNumber(int i) {...}
int n = 4;
std::function print1 = std::bind(&PrintNumber, n);
std::function print2 = std::bind(&PrintNumber, std::ref(n));
n = 5;
print1(); //prints 4
print2(); //prints 5
std::ref
is mainly used to encapsulate references when using std::bind
(but other uses are possible of course).