Ok, this is a tough question.
I have a C ++ class template that runs multiple times. For each of these instances, I need to execute a function that registers some operators. This needs to be done only once for a template instance before the first object of this template instance is used (which does not mean that it must be executed during instanciation that occurs during compilation).
So far, I have done this manually. But it is a pain. Therefore, I would like to automatically perform the registration function.
My current idea is to call a secure registration method in the constructor. However, with each instance of the class, it requires (small) overhead. Since this is done very often, I would like to avoid this overhead.
I also tried to use the static RAII helper element, but the static members of the template class were not constructed if they were not actively available, so this attempt failed.
Is there a way to execute code when initializing a class template (by a function or maybe a helper class RAII) without runtime overhead?
source share