#include <iostream>
constexpr int f(int line)
{
return line;
}
#define f() f(__LINE__)
int main(int argc, const char * argv[]) {
constexpr int x = f();
constexpr int y = f();
std::cout << "x = " << x << "; y = " << y;
return EXIT_SUCCESS;
}
Also, I don't think the language designers required"This lack of dependency must inherently mean that it will yield the same value upon each invocation having the same set of arguments"
to be true. http://en.cppreference.com/w/cpp/language/constexpr only states:
"The constexpr specifier declares that it is possible to evaluate the value of the function or variable at compile time."
The draft of the C++ standard on my system states that as follows:
"Certain contexts require expressions that satisfy additional requirements as detailed in this sub-clause. Such expressions are called constant expressions. [ Note: Those expressions can be evaluated during translation. — end note ]"