From 6e511725b79cbb961633b6d61491e72d6fad49b7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 28 Nov 2021 01:53:41 +0000 Subject: No global static for factory map --- lib/persistence.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/persistence.cpp b/lib/persistence.cpp index 5338738..239e425 100644 --- a/lib/persistence.cpp +++ b/lib/persistence.cpp @@ -6,25 +6,31 @@ namespace Persistence { using Factories = std::pair()>, std::function()>>; using NamedTypeFactories = std::map; - static NamedTypeFactories namedTypeFactories; + + inline static auto & + namedTypeFactories() + { + static NamedTypeFactories namedTypeFactories; + return namedTypeFactories; + } void Persistable::addFactory(const std::string_view t, std::function()> fu, std::function()> fs) { - namedTypeFactories.emplace(t, std::make_pair(std::move(fu), std::move(fs))); + namedTypeFactories().emplace(t, std::make_pair(std::move(fu), std::move(fs))); } std::unique_ptr Persistable::callFactory(const std::string_view t) { - return namedTypeFactories.at(t).first(); + return namedTypeFactories().at(t).first(); } std::shared_ptr Persistable::callSharedFactory(const std::string_view t) { - return namedTypeFactories.at(t).second(); + return namedTypeFactories().at(t).second(); } [[nodiscard]] std::string -- cgit v1.2.3