When answering this SO question, I found in the Standard (already C++03, still in C++11) that you can only use addresses as non-type template arguments if they\'re of the fo
Consider classes Foo<&X>
and Foo<&Y>
, both with a static member int Bar
. The linker must be able to tell whether your program has 1 or 2 Bar
objects. Now consider that the linker is also the party most likely responsible for assigning values to &X
and &Y
.
Look at the Standard again. As it's written, the compiler doesn't need to communicate the actual address to the linker. Instead, it passes the id-expression
. Linkers are already quite capable of determining whether two id-expression
's are the same, even before assigning a numerical address to them.
constexpr
, since the value of an address cannot be known at compile time; in most cases it will only be fixed after relocation prior to execution.&arr[i]
instead of arr + i
.