What about doing something like (live sample)
const int& MyConstValue(int x) {
static const int myConstValue = x;
return myConstValue;
}
int main() {
std::cout << MyConstValue(5) << std::endl; // This is the 1st call and "wins"
std::cout << MyConstValue(8) << std::endl;
return 0;
}
Output is
5
5
At least for c++11 this is even guaranteed to be thread safe.