No, this is not guaranteed.
However, you can:
template<typename T> std::vector<int>& registry() { static std::vector<int> reg; return reg; } ... registry<T>().push_back(i); ...
It is even better to avoid doing things that are too smart during startup.
Debugging before or after main is a true nightmare (and IMO doesn't even cover 100% in the standard). A simple registration may be fine, but never do anything that can fail.
Over the years, I have moved away from this approach to explicit initialization / shutdown and have never looked back.
source share