Skip to content

Commit

Permalink
Minor tweaks to leaf_detail::capture_list
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Dec 12, 2023
1 parent a146c9c commit c95f803
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
28 changes: 11 additions & 17 deletions include/boost/leaf/detail/capture_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ namespace leaf_detail
*last = this;
last = &next_;
}
};
node * first_;
} * first_;

template <class F>
BOOST_LEAF_CONSTEXPR void for_each( F f ) const
Expand All @@ -59,17 +58,6 @@ namespace leaf_detail
f(*p);
}

void clear() noexcept
{
for( node const * p = first_; p; )
{
node const * n = p -> next_;
delete p;
p = n;
}
first_ = nullptr;
}

public:

BOOST_LEAF_CONSTEXPR explicit capture_list( node * first ) noexcept:
Expand All @@ -85,18 +73,24 @@ namespace leaf_detail

~capture_list() noexcept
{
clear();
for( node const * p = first_; p; )
{
node const * n = p -> next_;
delete p;
p = n;
}
}

void unload( int const err_id )
{
capture_list moved(first_);
first_ = nullptr;
tls::write_uint<leaf_detail::tls_tag_id_factory_current_id>(unsigned(err_id));
for_each(
moved.for_each(
[err_id]( node & n )
{
n.unload(err_id);
n.unload(err_id); // last node may throw
} );
clear();
}

template <class CharT, class Traits>
Expand Down
11 changes: 6 additions & 5 deletions include/boost/leaf/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ namespace leaf_detail
BOOST_LEAF_ASSERT(last_ != nullptr);
BOOST_LEAF_ASSERT(*last_ == nullptr);
BOOST_LEAF_ASSERT(other.first_ == nullptr);
other.last_ = nullptr;
other.last_ = &other.first_;
}

template <class E>
Expand All @@ -364,18 +364,19 @@ namespace leaf_detail

bool empty() const noexcept
{
return last_ == &first_;
BOOST_LEAF_ASSERT(first_ != nullptr || last_ == &first_);
return first_ != nullptr;
}

int size() const noexcept
{
int n = 0;
int c = 0;
for_each(
[&]( capture_list::node const & )
{
++n;
++c;
} );
return n;
return c;
}

template <class T>
Expand Down

0 comments on commit c95f803

Please sign in to comment.