Suppose I have a class
struct X
{
static const X ZERO;
int value;
int square () const { return value * value; }
...
};
Then in one TU I define it as
const X X::ZERO { 0 };
However, other TU don't know anything about the value and so cannot, as I understand, optimize based on such knowledge, e.g. they can't say that X::ZERO.square()
is 0 at compile time.
Is it possible to somehow have a static field and still have its value known to all TU for optimization purposes? C++11 is fine.