From 56207fbf4e8662b6cf93632193ba68d2576c2d4e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 1 Apr 2026 12:07:58 +0100 Subject: Helper to instantiate transient static values as required --- lib/util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/util.h b/lib/util.h index cd7971b..b60b093 100644 --- a/lib/util.h +++ b/lib/util.h @@ -3,6 +3,7 @@ #include // IWYU pragma: keep #include #include +#include #include template @@ -33,3 +34,14 @@ template inline constexpr auto Nth = GetNth {}; inline constexpr auto GetFirst = Nth<0>; inline constexpr auto GetSecond = Nth<1>; inline constexpr auto GetSwapped = Nth<0, 1>; + +template +bool +createIfRequired(std::shared_ptr & instance, std::weak_ptr & common) +{ + if (!instance && !(instance = common.lock())) { + common = instance = std::make_shared(); + return true; + } + return false; +} -- cgit v1.3