#include #include #include #include class SingletonManager { public: // Priority: Higher numbers are destroyed LAST (e.g., Logger = 100) static void registerShutdown(const int priority, const std::function& shutdownFunc) { m_registry.push_back({priority, shutdownFunc}); // Sort so that high priority stays at the end (destroyed last) std::ranges::sort(m_registry, [](const auto& a, const auto& b) { return a.priority < b.priority; }); } static void shutdownAll() { // Destroy in reverse priority (highest priority first? No, usually // reverse order of arrival) Here we destroy from lowest priority to // highest. for (auto& [priority, func] : m_registry) { std::cerr << priority << ": " << &func << std::endl; func(); } m_registry.clear(); } private: struct Entry { int priority; std::function func; }; static inline std::vector m_registry; };