void g();
int f(const int &x) {
int y = x;
g();
return x + y;
}
Here, the value in x has to be loaded twice before and after g() because g is allowed to modify the value referenced by x.
You can do an explicit load to avoid the problem.
int f(const int &rx) {
int x = rx;
int y = x;
g();
return x + y;
}
But C++ has developed in a way that you don't have to write down such details and still have performant code.
Is there a way to tell the compiler in the declaration of x, that the value being referenced will not change over external function calls?