diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-04-01 12:07:58 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-04-01 12:07:58 +0100 |
| commit | 56207fbf4e8662b6cf93632193ba68d2576c2d4e (patch) | |
| tree | dec327a00b301149e76f691728053c7ef5bb9119 /lib | |
| parent | Move light vertex structs out (diff) | |
| download | ilt-56207fbf4e8662b6cf93632193ba68d2576c2d4e.tar.bz2 ilt-56207fbf4e8662b6cf93632193ba68d2576c2d4e.tar.xz ilt-56207fbf4e8662b6cf93632193ba68d2576c2d4e.zip | |
Helper to instantiate transient static values as required
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/util.h | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -3,6 +3,7 @@ #include <algorithm> // IWYU pragma: keep #include <array> #include <cstddef> +#include <memory> #include <tuple> template<typename T, std::size_t N> @@ -33,3 +34,14 @@ template<size_t... N> inline constexpr auto Nth = GetNth<N...> {}; inline constexpr auto GetFirst = Nth<0>; inline constexpr auto GetSecond = Nth<1>; inline constexpr auto GetSwapped = Nth<0, 1>; + +template<typename T> +bool +createIfRequired(std::shared_ptr<T> & instance, std::weak_ptr<T> & common) +{ + if (!instance && !(instance = common.lock())) { + common = instance = std::make_shared<T>(); + return true; + } + return false; +} |
