Hi, I am attempting to initialize a static runtime variable that is initialized in every class via a member static variable that is in-turn initialized via a static dispatcher function.

For the most part, everything works – but I have encountered an unexpected caveat – the static variable of a template is not initialized on template instantiation, only on access of the internal variable. This is something I want to be done automatically so that you do not have to do any additional instantiation work for every possible template variant used in code…

 

An example of this attempt can be seen here: https://godbolt.org/z/Mb3hr576z

 

Currently, the only two ways I can think of are shown in the example below:
(1) manually touch the static member in any code

(2) same as 1, but we simply touch it in the default constructor

However, both examples require code modification *outside* of the STATIC_BODY macro. I would like to constrain it to be within if possible.

Is anyone aware of any techniques/compiler that can be used to force to initialize templated statics on initialization?