If you want to distinguish between a compilation time constant and a time constant other than compilation, then you have no chance. It's impossible.
But if you want to distinguish between a variable variable and a constant variable (and everything else is just literals), then you can overload the function with a reference to const-reference and non-const. For this scenario, the C ++ standard introduces additional rules that make this case ambiguous, but not ambiguous.
void f(int const&);
The following decisions are made in this matter.
int x = 0; int const y = x; int const z = 1; f(1);
Note that it cannot distinguish between y and z, although z is a compile-time constant (called an integral constant expression or ICE), but y is not.
What you can do is just take compile time values. Overload the function so that it is a template and the other is not
template<int N> void f();
Then he behaves like this:
int x = 0; int const y = x; int const z = 1; f<1>();
Johannes Schaub - litb
source share