From 3c91f086090390930bba62c6512c4e74a5520e76 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sun, 16 Jul 2023 17:30:06 -0400 Subject: [PATCH] delays initialization of mohndle's null_storage_ until first use, to support the case where main needs to be entered before first use --- btas/util/mohndle.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/btas/util/mohndle.h b/btas/util/mohndle.h index 9646eca8..f895c6cc 100644 --- a/btas/util/mohndle.h +++ b/btas/util/mohndle.h @@ -195,7 +195,7 @@ namespace btas { [](auto&& v) -> const Storage* { using v_t = std::remove_reference_t; if constexpr (std::is_same_v || std::is_same_v) { - return &null_storage_; + return &null_storage(); } else if constexpr (std::is_same_v) { return &v; } else if constexpr (std::is_same_v) { @@ -294,7 +294,11 @@ namespace btas { } #endif - inline static Storage null_storage_ = {}; // used if this is null + /// delays construction of null storage object until first use + static Storage& null_storage() { + static Storage null = {}; + return null; + } }; template >>