Skip to content

Commit

Permalink
Add is_valid() helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Apr 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 051441a commit 853d22e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions include/tanuki/tanuki.hpp
Original file line number Diff line number Diff line change
@@ -1620,9 +1620,8 @@ class TANUKI_VISIBLE wrap : private detail::wrap_storage<IFace, Cfg.static_size,
wrap &operator=(invalid_wrap_t) noexcept
{
if constexpr (Cfg.semantics == wrap_semantics::value) {
// Don't do anything if this is already
// in the invalid state.
if (!is_invalid(*this)) {
// Do something only if this is in a valid state.
if (is_valid(*this)) {
// Destroy the contained value.
destroy();

@@ -1720,7 +1719,7 @@ class TANUKI_VISIBLE wrap : private detail::wrap_storage<IFace, Cfg.static_size,
{
if constexpr (Cfg.semantics == wrap_semantics::value) {
// Destroy the value in w if necessary.
if (!is_invalid(w)) {
if (is_valid(w)) {
w.destroy();
}

@@ -1983,6 +1982,12 @@ template <typename Holder, typename U>
}
}

template <typename IFace, auto Cfg>
bool is_valid(const wrap<IFace, Cfg> &w) noexcept
{
return !is_invalid(w);
}

template <typename IFace, auto Cfg>
bool has_dynamic_storage(const wrap<IFace, Cfg> &w) noexcept
{

0 comments on commit 853d22e

Please sign in to comment.