Will my program contain 100 copies of each row and array if I include it in 100 units? Or will only pointers and values ββbe copied?
The standard does not promise the consolidation of string literals, so before implementation. A simple test using GCC 5.1.1 on GNU / Linux showed that string literals are not combined into an unoptimized assembly, but are consolidated using -O or -Os . But this is just a merge of real char arrays. To the extent that the compiler does not optimize storage for a pointer or for numeric constants (if they are local to the translation unit and not to ODR and POD type, they are obvious candidates for elimination according to as-if), however, the compiler may not be able to easily consolidate them. The standard requires that they be different objects and, therefore, must have different addresses. The as-if rule can still allow them to be deleted even if you have to accept their addresses, but this usually requires global optimization of the programs, as well as optimization of connection time, including libraries that the implementation may not support, only support in a limited way, / or only depending on the compiler and linker settings. In other words, this can happen under the right circumstances, but it is much more likely that this will not happen.
My own test shows that GCC 5.1.1 does not combine static const unsigned int objects exposed by const ref, even with -Os -flto (optimize size and enable bind time optimization). I would be frankly surprised if some modern implementation really performed this complex and obscure optimization.
(I also assume that βstaticβ is redundant in this use, but I like it there anyway)
This is not redundant if you have several translation units, because otherwise you could work with one definition rule (ODR). However, as a side note, the static in the namespace has been considered syntactically obsolete for a long time (consider using anonymous namespaces introduced in C ++ 98).
(in response to Cheers and hth. - Alf)
If you want to provide only one copy of each constant or even no copy, you can use a template template, for example:
There is no such luck. There is no guarantee in the standard how much space is used for templates. The entire template ensures that only one of the potentially many copies is used - or, apparently, used according to the as-if rule. This is actually worse because at least GCC 5.1.1 does not actually remove the excess static const unsigned int even with -Os -flto on my system. This means that with two translation units, the initializer value for unsigned int can be found in two different places, although only one of them is used (all pointers and links refer only to this location).