Skip to content

Commit

Permalink
🎨 made super's members private
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Dec 5, 2024
1 parent 74ffe2b commit 5d78d88
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions ashura/std/super.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ struct Super
}
};

alignas(ALIGNMENT) mutable u8 storage[CAPACITY];
alignas(ALIGNMENT) mutable u8 storage_[CAPACITY];

Base * base_ptr;
Base * base_;

Lifecycle lifecycle;
Lifecycle lifecycle_;

template <typename Object>
requires (Derives<Object, Base> && ALIGNMENT >= alignof(Object) &&
Expand All @@ -63,11 +63,11 @@ struct Super
template <usize SrcAlignment, usize SrcCapacity>
requires (ALIGNMENT >= SrcAlignment && CAPACITY >= SrcCapacity)
constexpr Super(Super<Base, SrcAlignment, SrcCapacity> && other) :
lifecycle{other.lifecycle}
lifecycle_{other.lifecycle_}
{
other.lifecycle(other.storage, storage, &base_ptr);
other.lifecycle = noop;
other.base_ptr = nullptr;
other.lifecycle_(other.storage_, storage_, &base_);
other.lifecycle_ = noop;
other.base_ = nullptr;
}

template <usize SrcAlignment, usize SrcCapacity>
Expand All @@ -82,28 +82,28 @@ struct Super
}
}

lifecycle(storage, nullptr, nullptr);
other.lifecycle(other.storage, storage, &base_ptr);
lifecycle = other.lifecycle;
other.lifecycle = noop;
other.base_ptr = nullptr;
lifecycle_(storage_, nullptr, nullptr);
other.lifecycle_(other.storage_, storage_, &base_);
lifecycle_ = other.lifecycle_;
other.lifecycle_ = noop;
other.base_ = nullptr;

return *this;
}

constexpr operator Base &() const
{
return *base_ptr;
return *base_;
}

constexpr Base & get() const
{
return *base_ptr;
return *base_;
}

constexpr ~Super()
{
lifecycle(storage, nullptr, nullptr);
lifecycle_(storage_, nullptr, nullptr);
}
};

Expand Down

0 comments on commit 5d78d88

Please sign in to comment.