Skip to content

Commit

Permalink
delays initialization of mohndle's null_storage_ until first use, to …
Browse files Browse the repository at this point in the history
…support the case where main needs to be entered before first use
  • Loading branch information
evaleev committed Jul 16, 2023
1 parent 5a45699 commit 3c91f08
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions btas/util/mohndle.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace btas {
[](auto&& v) -> const Storage* {
using v_t = std::remove_reference_t<decltype(v)>;
if constexpr (std::is_same_v<v_t, std::monostate> || std::is_same_v<v_t, std::monostate const>) {
return &null_storage_;
return &null_storage();
} else if constexpr (std::is_same_v<v_t, Storage>) {
return &v;
} else if constexpr (std::is_same_v<v_t, Storage const>) {
Expand Down Expand Up @@ -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 <typename Storage, typename = std::enable_if_t<!std::is_const_v<Storage>>>
Expand Down

0 comments on commit 3c91f08

Please sign in to comment.