Skip to content

Commit

Permalink
karm-base: Defer Cow<T> base construction.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Oct 31, 2024
1 parent 870fb08 commit 00a05f8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/libs/karm-base/cow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ namespace Karm {

template <typename T>
struct Cow {
static Strong<T> BASE;
Strong<T> _inner = BASE;
Strong<T> _inner = base();

static Opt<Strong<T>> _base;

static Strong<T> base() {
if (not _base) {
_base = makeStrong<T>();
}
return _base.unwrap();
}

T &cow() {
if (_inner.refs() > 1)
Expand All @@ -29,7 +37,7 @@ struct Cow {
};

template <typename T>
Strong<T> Cow<T>::BASE = makeStrong<T>();
Opt<Strong<T>> Cow<T>::_base = NONE;

template <typename T>
Cow<T> makeCow(T const &value) {
Expand Down

0 comments on commit 00a05f8

Please sign in to comment.